Android: Using media files for grid view tutorial causes it to run out of memory after 9 pics?
<p>I'm trying to learn how to display all the images stored on an android phone in a grid view (my goal is to have a user select which image they want to process).</p>

<p>I am adapting the tutorial at:</p>

<p><a href="http://developer.android.com/resources/tutorials/views/hello-gridview.html" rel="nofollow">http://developer.android.com/resources/tutorials/views/hello-gridview.html</a></p>

<p>to do so.</p>

<p><a href="http://pastie.org/2504664" rel="nofollow">http://pastie.org/2504664</a></p>

<p>Above is a link to my modified ImageAdapter class (the only thing I believe needs to be changed).</p>

<p>In it, rather than having an integer array of Resources ids, I have a string array of media file locations, and turn them into a bitmap like so:</p>

<pre><code>imageView.setImageBitmap(BitmapFactory.decodeFile(picture_paths[position]));
</code></pre>

<p>I'm getting the file locations in the first place by:</p>

<pre><code>   public void populateArray(){
      Log.v("Jenny","Populating array");
      picture_paths = new String[getCount()];
      cursor.moveToFirst();
      int count = 0;
      while(!cursor.isLast() ){
          count ++;
          picture_paths[cursor.getPosition()] = cursor.getString(0);
          cursor.moveToNext();
      }

}
</code></pre>

<p>It works like a gem, as long as I have less than 9 pictures (in three columns of three).</p>

<p>Any more than that, and the thing crashes with an "Out of Memory" error.  If I just follow the tutorial and use resource images, I can have as many as I like, it seems.</p>

<p>So: Am I going about this the wrong way?  Is loading it as a Bitmap to intensive? What alternatives are there? </p>

<p>Displaying the images stored on the phone seems like a really trivial, basic task. What is the "right" way to do this, and is there anyway I can make this way work?</p>

<p>Edit:  Testing on my second phone (a Galaxy) makes things work just fine (can display any number of images, though it seems like sometimes the file path retrieved by the cursor are 'null').  On my original testing phone (a myTouch) I get the memory error no matter how I attempt to display the images (drawable, bitmaps, whatever).  Why would I get different behaviors on the two phones?</p>

<p>Edit: Well, one thing that might be going on is that my myTouch has more pictures on it? I took a few more pics with my Galaxy and now it is getting out of memory errors as well.... Is grid view not for displaying photos (if not, what good is it?)</p>

<p>Still limited to 9 on myTouch but can go to 11 on Galaxy</p>

<p>Both crash with an out of Memory error when rotated (i.e the view redraws). (though not with a small amount of pics (less than 6 maybe?)</p>
