Question: Every time I run my app in Xcode on the iOS Simulator, the folders in the project navigation pane all reset to just showing the closed top-level folders. 

I then have to re-drill-down to the code, opening all the folders on the way; but then when I run the app again we're back to square one.

There's presumably a really obvious settings button somewhere that I'm missing and have hit by accident, as I don't recall it doing this in the past. Can anyone point me towards it?

Answer: 
A bitmap takes up 4 bytes per pixel ==> 13MP equals 52MB of memory.
You should use BitmapFactory.Options to get the size only first. By using `inJustDecodeBounds` you get the Bitmap object with all its meta data, but without the actual image.

```
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;

```

then calculate the scale size that your screen needs:

```
public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

    final int halfHeight = height / 2;
    final int halfWidth = width / 2;

    // Calculate the largest inSampleSize value that is a power of 2 and keeps both
    // height and width larger than the requested height and width.
    while ((halfHeight / inSampleSize) > reqHeight
            && (halfWidth / inSampleSize) > reqWidth) {
        inSampleSize *= 2;
    }
}

return inSampleSize;
}

```

and use that to load a scaled version of your bitmap:

```
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
        int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}

```

This is all explained in the [Developer Guide](http://developer.android.com/training/displaying-bitmaps/load-bitmap.htmlhttp://developer.android.com/training/displaying-bitmaps/load-bitmap.html)
```
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;

```

To avoid `java.lang.OutOfMemory` exceptions, check the dimensions of a bitmap before decoding it, unless you absolutely trust the source to provide you with predictably sized image data that comfortably fits within the available memory. [Reference](http://developer.android.com/training/displaying-bitmaps/load-bitmap.html)