Android app stops without error on orientation change
<p>I'm developing an app that makes use of the Google maps API.  I've developed two separate layouts to handle both types of orientation (portrait and landscape).  Everything works fine except I'm having a very strange bug.  </p>

<p>Sometimes, when I flip the phone from portrait to landscape or vice versa, the app will simply close.  There's no error visible on the screen.  There's no exception thrown in Logcat.  It's almost as if my app simply calls <code>finish()</code> and quits (which isn't anywhere in the program).  I also am not trying to save any state on rotation yet, so as of right now the app effectively restarts.  Sometimes, I'll flip it 50 times before this happens, and sometimes twice.</p>

<p>The only thing I can find on this problem is this:
<a href="http://stackoverflow.com/questions/5148259/android-screen-orientation-change-causes-app-to-quit">Android Screen Orientation Change Causes App To Quit</a></p>

<p>It doesn't really help at all.</p>

<p>There is, however, one large message that pops up in the normal log.</p>

<pre><code>I/DEBUG   (24223): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (24223): Build fingerprint: 'sprint/htc_supersonic/supersonic/supersonic:2.2/FRF91/294884:user/release-keys'
I/DEBUG   (24223): pid: 24329, tid: 24329  &gt;&gt;&gt; ---name of my package--- &lt;&lt;&lt;
I/DEBUG   (24223): signal 11 (SIGSEGV), fault addr 00000000
I/DEBUG   (24223):  r0 005003d0  r1 00000000  r2 00000000  r3 005003f4
I/DEBUG   (24223):  r4 005003d0  r5 00000000  r6 00000000  r7 00000000
I/DEBUG   (24223):  r8 be8ae130  r9 4187369c  10 41873688  fp be8ae478
I/DEBUG   (24223):  ip 005003d0  sp be8adef8  lr 00000000  pc ab14b0e4  cpsr 60000010
I/DEBUG   (24223):  d0  6472656767756265  d1  6f6c6c6120737562
I/DEBUG   (24223):  d2  6f6f74206e6f6979  d3  6620656772616c74
I/DEBUG   (24223):  d4  0000000044340000  d5  4448000044340000
I/DEBUG   (24223):  d6  3fc000003fc00000  d7  4080000080000000
I/DEBUG   (24223):  d8  000002d044961000  d9  0000000000000000
I/DEBUG   (24223):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   (24223):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   (24223):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   (24223):  d16 00000000460b1918  d17 bff0000000000000
I/DEBUG   (24223):  d18 3ff0000000000000  d19 0000000000000000
I/DEBUG   (24223):  d20 0000000000000000  d21 0000000000000000
I/DEBUG   (24223):  d22 3ff0000000000000  d23 0000000000000000
I/DEBUG   (24223):  d24 3ff0000000000000  d25 0000000000000000
I/DEBUG   (24223):  d26 0000000000000000  d27 0000000000000000
I/DEBUG   (24223):  d28 0008000a00050002  d29 0003000b000d0009
I/DEBUG   (24223):  d30 001f001f001f001f  d31 001f001f001f001f
I/DEBUG   (24223):  scr 68000012
I/DEBUG   (24223):
I/DEBUG   (24223):          #00  pc 0004b0e4  /system/lib/libskia.so
I/DEBUG   (24223):          #01  pc 0004b1a8  /system/lib/libskia.so
I/DEBUG   (24223):          #02  pc 0006896c  /system/lib/libskia.so
I/DEBUG   (24223):          #03  pc 0006434c  /system/lib/libskia.so
I/DEBUG   (24223):          #04  pc 0004f7c0  /system/lib/libandroid_runtime.so
I/DEBUG   (24223):
I/DEBUG   (24223): code around pc:
I/DEBUG   (24223): ab14b0c4 e1500001 e92d4070 e1a05001 e1a04000
I/DEBUG   (24223): ab14b0d4 0a00001a e1a06005 ebffff9f e1a0c004
I/DEBUG   (24223): ab14b0e4 e8b6000f e8ac000f e8b6000f e8ac000f
I/DEBUG   (24223): ab14b0f4 e8960003 e88c0003 e5950004 e3500000
I/DEBUG   (24223): ab14b104 0a000001 e2800004 ebff7655 e5950000
I/DEBUG   (24223):
I/DEBUG   (24223): code around lr:
I/DEBUG   (24223):
I/DEBUG   (24223): stack:
I/DEBUG   (24223):     be8adeb8  afd4372c  /system/lib/libc.so
I/DEBUG   (24223):     be8adebc  0000003b
I/DEBUG   (24223):     be8adec0  005003c8  [heap]
I/DEBUG   (24223):     be8adec4  00000000
I/DEBUG   (24223):     be8adec8  be8ae130  [stack]
I/DEBUG   (24223):     be8adecc  4187369c
I/DEBUG   (24223):     be8aded0  41873688
I/DEBUG   (24223):     be8aded4  afd0c737  /system/lib/libc.so
I/DEBUG   (24223):     be8aded8  005003d0  [heap]
I/DEBUG   (24223):     be8adedc  00000000
I/DEBUG   (24223):     be8adee0  00000000
I/DEBUG   (24223):     be8adee4  ab14af6c  /system/lib/libskia.so
I/DEBUG   (24223):     be8adee8  005003d0  [heap]
I/DEBUG   (24223):     be8adeec  00000000
I/DEBUG   (24223):     be8adef0  df002777
I/DEBUG   (24223):     be8adef4  e3a070ad
I/DEBUG   (24223): #00 be8adef8  005003d0  [heap]
I/DEBUG   (24223):     be8adefc  be8adf5c  [stack]
I/DEBUG   (24223):     be8adf00  00000000
I/DEBUG   (24223):     be8adf04  ab14b1ac  /system/lib/libskia.so
I/DEBUG   (24223): #01 be8adf08  005003c8  [heap]
I/DEBUG   (24223):     be8adf0c  ab168970  /system/lib/libskia.so
I/DEBUG   (24223): debuggerd committing suicide to free the zombie!
I/DEBUG   (24516): debuggerd: Dec  8 2010 19:11:01
I/BootReceiver(  114): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
I/ActivityManager(  114): Process --- name of my package --- (pid 24329) has died.
D/Zygote  (   63): Process 24329 terminated by signal (11)
E/ActivityManager(  114): fail to set top app changed!
D/Sensors (  114): close_akm, fd=122
I/UsageStats(  114): Unexpected resume of com.htc.launcher while already resumed in  --- name of my package ---
W/InputManagerService(  114): Got RemoteException sending setActive(false) notification to pid 24329 uid 10109
</code></pre>

<p>From the looks of it, my app is trying to access memory address <code>00000000</code> and is throwing a segmant fault.</p>

<p>I'm running Android 2.2 on a HTC Evo 4G.  I haven't been able to test the app on other hardware yet, but I'd like to find out why it's crashing at all.</p>

<p><strong>EDIT:</strong></p>

<p>I ran the test on the emulator.  Now, I get an OutOfMemory exception for loading bitmaps.  I only load two bitmaps programmatically.  Everything else is through xml.</p>

<pre><code>E/AndroidRuntime(  613): FATAL EXCEPTION: main
E/AndroidRuntime(  613): java.lang.RuntimeException: Unable to start activity ComponentInfo{---package name---/-- activity name ---}: android.view.InflateException: Binary XML file line #19: Error inflating class &lt;unknown&gt;
E/AndroidRuntime(  613):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  613):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  613):        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3815)
E/AndroidRuntime(  613):        at android.app.ActivityThread.access$2400(ActivityThread.java:125)
E/AndroidRuntime(  613):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
E/AndroidRuntime(  613):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  613):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  613):        at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  613):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  613):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  613):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  613):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  613):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  613): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class &lt;unknown&gt;
E/AndroidRuntime(  613):        at android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime(  613):        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime(  613):        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
E/AndroidRuntime(  613):        at android.app.Activity.setContentView(Activity.java:1647)
E/AndroidRuntime(  613):        at --- activity name ---.onCreate(--- activity name ---.java:92)
E/AndroidRuntime(  613):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  613):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  613):        ... 12 more
E/AndroidRuntime(  613): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(  613):        at android.widget.RelativeLayout.&lt;init&gt;(RelativeLayout.java:170)
E/AndroidRuntime(  613):        at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime(  613):        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.createView(LayoutInflater.java:500)
E/AndroidRuntime(  613):        ... 23 more
E/AndroidRuntime(  613): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(  613):        at android.graphics.Bitmap.nativeCreate(Native Method)
E/AndroidRuntime(  613):        at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
E/AndroidRuntime(  613):        at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
E/AndroidRuntime(  613):        at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
E/AndroidRuntime(  613):        at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
E/AndroidRuntime(  613):        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
E/AndroidRuntime(  613):        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
E/AndroidRuntime(  613):        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
E/AndroidRuntime(  613):        at android.content.res.Resources.loadDrawable(Resources.java:1709)
E/AndroidRuntime(  613):        at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime(  613):        at android.view.View.&lt;init&gt;(View.java:1885)
E/AndroidRuntime(  613):        at android.view.View.&lt;init&gt;(View.java:1834)
E/AndroidRuntime(  613):        at android.view.ViewGroup.&lt;init&gt;(ViewGroup.java:285)
E/AndroidRuntime(  613):        ... 27 more
</code></pre>

<p>Line 92 of my activity is <code>setContentView(R.layout.main)</code>, so it seems to crash when it inflates the main layout.  It's having problems loading the bitmaps I use for backgrounds.  How do I dump the memory of the bitmaps or reuse them?  I'm not controlling those from the program, so it's all automated on Android's part.</p>
