retrieve image from gallery in android
<p>I have created an <code>Activity</code> where i have a <code>Button</code>.</p>

<p>By pressing the button an android <code>Gallery</code> opens. When i choose an image from the gallery it is shows it in an <code>ImageView</code> of my <code>Activity</code> but after choosing second time the following error occuring</p>

<pre><code>01-13 17:55:25.323: ERROR/AndroidRuntime(14899): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
</code></pre>

<p>Here is the source code i am using:</p>

<pre><code>public class MyImage extends Activity {
    /** Called when the activity is first created. */
    Gallery gallery;
     private Uri[] mUrls;  
    String[] mFiles=null;  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

          File images = Environment.getDataDirectory();  
                 File[] imagelist = images.listFiles();  

                  mFiles = new String[imagelist.length];  

                          for(int i= 0 ; i&lt; imagelist.length; i++)  
                          {  
                              mFiles[i] = imagelist[i].getAbsolutePath();  
                          }  
                          mUrls = new Uri[mFiles.length];  

                          for(int i=0; i &lt; mFiles.length; i++)  
                          {  
                              mUrls[i] = Uri.parse(mFiles[i]);     
                          }     

                          Gallery g = (Gallery) findViewById(R.id.Gallery01);  
                          g.setAdapter(new ImageAdapter(this));  
                          g.setFadingEdgeLength(40);  
    }

     public class ImageAdapter extends BaseAdapter{  

                 int mGalleryItemBackground;  
                 public ImageAdapter(Context c)  {     
                     mContext = c;     
                 }  
                 public int getCount(){  
                     return mUrls.length;  
                 }  
                 public Object getItem(int position){  
                     return position;  
                 }  
                 public long getItemId(int position) {  
                     return position;  
                 }  
                public View getView(int position, View convertView, ViewGroup parent){  
                     ImageView i = new ImageView(mContext);  

                     i.setImageURI(mUrls[position]);  
                     i.setScaleType(ImageView.ScaleType.FIT_XY);  
                     i.setLayoutParams(new Gallery.LayoutParams(260, 210));  
                     return i;  
                 }     
                 private Context mContext;  
                 }     
}
</code></pre>
