android bitmap caching
<p>I would like to load images into a gallery view from a url?</p>

<p>I first make them a bitmap using this.</p>

<pre><code>URL aURL = new URL(myRemoteImages[position]);
URLConnection conn = aURL.openConnection();
conn.setUseCaches(true);
conn.connect();
Object response = conn.getContent();
if (response instanceof Bitmap) {
    Bitmap bm = (Bitmap)response;

    InputStream is = conn.getInputStream();  
    /* Buffered is always good for a performance plus. */
    BufferedInputStream bis = new BufferedInputStream(is);
    /* Decode url-data to a bitmap. */

    bm = BitmapFactory.decodeStream(bis);
    bis.close();
    is.close();
    Log.v(imageUrl, "Retrieving image");

    /* Apply the Bitmap to the ImageView that will be returned. */
    i.setImageBitmap(bm);
</code></pre>

<p>How could I go about caching this bitmap? So when the user swipes the screen it doesn't reload over and over?</p>

<p>EDIT: I CALL getImage() to retreive the text url for each url.</p>

<p>i use both of these in a asyncTask. preExecute i call getImage()
and doInBackground i set the gallery to the imageAdapter.</p>

<pre><code>    private class MyTask extends AsyncTask&lt;Void, Void, Void&gt;{


                @Override
                protected Void doInBackground(Void... arg0) {try {
                            getImages();
                            Log.v("MyTask", "Image 1 retreived");
                            getImage2();
                            Log.v("MyTask", "Image 2 retreived");
                            getImage3();
                            Log.v("MyTask", "Image 3 retreived");
                            getImage4();
                            Log.v("MyTask", "Image 4 retreived");
                        } catch (IOException e) {
                            Log.e("MainMenu retreive image", "Image Retreival failed");
                            e.printStackTrace();
                        }
                    return null;
                }
                @Override

                protected void onPostExecute(Void notUsed){
                    ((Gallery) findViewById(R.id.gallery))
                          .setAdapter(new ImageAdapter(MainMenu.this));


                }

                        }
</code></pre>

<p>EDIT: getView() method</p>

<pre><code>    public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(this.myContext);

                try {

                                URL aURL = new URL(myRemoteImages[position]);
                                URLConnection conn = aURL.openConnection();
                                conn.setUseCaches(true);
                                conn.connect();
                                Object response = conn.getContent();
                                if (response instanceof Bitmap) {
                                  Bitmap bm = (Bitmap)response;
</code></pre>
