Facing "trying to use a recycled bitmap" exception while using XML as drawable
<p>I'm trying to set an xml file as a <code>RelativeLayout</code>'s background image. To do this, I have to convert the xml to a drawable.</p>

<p>This is what I've done...</p>

<pre><code>    RelativeLayout content = (RelativeLayout) findViewById(R.id.background);
    // "content" is the xml file (which is currently displayed), that I want to use as the background image.
    content.setDrawingCacheEnabled(true);
    Bitmap bitmap = content.getDrawingCache();
    content.setDrawingCacheEnabled(false);
    Drawable d = new BitmapDrawable(getResources(), bitmap);

    // Now I'm changing layouts to the one that has the Relative Layout of which I want to add the xml/drawable background.
    mvf.setDisplayedChild(0);

    // The layout of which I want to add the xml/drawable background.
    (findViewById(R.id.root)).setBackground(d);
</code></pre>

<p>These are the errors I'm getting.</p>

<pre><code>W/Bitmap: Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
W/Bitmap: Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@d5316ab
</code></pre>