Android caching method
<p>In my application there is a set amount of images that need cached. It is about 12 - 15 images I will need cached tops. What I have done is store the image in a file in a directory on the device like this.</p>

<pre><code>    FileOutputStream o = new FileOutputStream(getFilesDir().getAbsolutePath()
                + "/background.txt");
        Bitmap b = getBitmapFromURL("http://10.84.4.2:8083/images/General/background.png");
        b.compress(Bitmap.CompressFormat.PNG, 90, o);
</code></pre>

<p>Then just reload the image when I need it like this</p>

<pre><code>BitmapDrawable bg  = new BitmapDrawable(BitmapFactory.decodeFile(c
                .getFilesDir().getAbsolutePath() + "/background.txt"));
</code></pre>

<p>I download the images all at once using Asynch Task like this</p>

<pre><code>public class DownloadImagesTask extends AsyncTask&lt;String, String, Bitmap&gt;
{

    Bitmap bmp;
    String name;

    @Override
    protected Bitmap doInBackground(String... urls)
    {
        name = urls[1];
        return download_Image(urls[0]);
    }

    @Override
    protected void onPostExecute(Bitmap result)
    {
        try
        {

            FileOutputStream o = new FileOutputStream(getFilesDir()
                    .getAbsolutePath() + name);
            result.compress(Bitmap.CompressFormat.PNG, 90, o);
        } catch (Exception e)
        {
            e.printStackTrace();
        }

    }

    private Bitmap download_Image(String url)
    {
        return bmp = getBitmapFromURL(url);

    }

}
</code></pre>

<p>My question is, is this a bad way of doing this? I tried finding good tutorials about caching online, but found it difficult to find a full tutorial that actually explained it properly. The method I am using seems quite simple, but not sure if it is recommended.</p>

<p>Would be grateful if anyone could tell me what are the pros and cons of doing it my way, and should I consider changing to another method.</p>

<p>Thanks</p>
