title: Black Screen After Restart
body: <p>I've a strange black screen problem at app restart after the app wasn't used for a while reported by users in the play store developer console with an ANR with a quite strange stack trace:</p>
  
  <pre><code>----- pid 2704 at 2013-08-15 09:08:32 -----
  Cmd line: system_server
  
  DALVIK THREADS:
  (mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
  "main" prio=5 tid=1 NATIVE
    | group="main" sCount=1 dsCount=0 obj=0x400281b8 self=0xd088
    | sysTid=2704 nice=0 sched=0/0 cgrp=default handle=-1345006464
    | schedstat=( 29713532638 35237133707 131286 )
    at com.android.server.SystemServer.init1(Native Method)
    at com.android.server.SystemServer.main(SystemServer.java:918)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(...)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
    at dalvik.system.NativeStart.main(Native Method)
   ...
  </code></pre>
  
  <p>and no thread with app code involved. I can kind of reproduce it on one of my test devices but it is quite random and takes really long to run into the error. But if I'm able to I get the following messages in the log of the device right after starting the app:</p>
  
  <pre><code>I/ActivityManager( 2704): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.client.android/.ExampleMainActivity bnds=[125,494][235,632] } from pid 2908
  W/ActivityManager( 2704): Receiver during timeout: BroadcastFilter{40b8b180 ReceiverList{40b8b108 32495 com.example.client.android/10107 remote:40b34b28}}
  I/ActivityManager( 2704): Skipping duplicate ANR: ProcessRecord{40bfc8c0 32495:com.example.client.android/10107} Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x40000000 }
  W/ActivityManager( 2704): Activity idle timeout for HistoryRecord{40578b78 com.example.client.android/.ExampleMainActivity}
  </code></pre>
  
  <p>I already googled around and found the following posts on StackOverflow concerning these messages:</p>
  
  <p><a href="https://stackoverflow.com/questions/4283449/activity-idle-timeout-for-historyrecord">Activity idle timeout for HistoryRecord?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3447729/activity-idle-timeout-for-historyrecord">Activity idle timeout for HistoryRecord</a></p>
  
  <p>And the following post in google groups:</p>
  
  <p><a href="https://groups.google.com/forum/?fromgroups#!topic/android-developers/TfkPlN5b-ig" rel="nofollow noreferrer">https://groups.google.com/forum/?fromgroups#!topic/android-developers/TfkPlN5b-ig</a></p>
  
  <p>I checked for services, if there's anything heavy-weight in onReceive of the <code>BroadcastReceivers</code> but haven't found anything.</p>
  
  <p>We use a <code>OnGlobalChangeLayoutListener</code>, which applied an <code>View.invalidate()</code> to work around a <code>WebView</code> repaint probelm which maybe could cause a draw-Looping. I removed it but still do get the problem. </p>
  
  <p>Anyone maybe having the same problem and having an idea how to fix it or to isolate it? I'm pretty much out of ideas here and would love to understand what's going on here.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I forgot to mention: if this black screen problem happened the only way getting the app out of this is a forced stop of the application process. Otherwise the log lines get logged every time I try to start the app.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>A more detailed description of what is happening as requested: The black screen occurs very randomly. It always happens at start of the app and if happened only a force stop gets the app out of this. It seems to happen only after the app wasn't used for a longer and was probably swapped out of memory. And it looks like only Android 2.x devices are affected although I'm not sure with this.</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>I've added a button which calls <code>android.os.Process.killProcess(Process.myPid());</code> and if I call this again and again I've been able to reproduce it after some time, by starting the app and quitting it using the button. After some time (quite random), I get this right after quitting using the button:</p>
  
  <pre><code>E/JavaBinder( 2704): !!! FAILED BINDER TRANSACTION !!!
  </code></pre>
  
  <p>followed by a:</p>
  
  <pre><code>W/ActivityManager( 2704): Activity pause timeout for HistoryRecord{40976dd8 com.example.client.android/.ExampleMainActivity}
  </code></pre>
  
  <p>and next time I restart the app I just get a black screen and the log messages mentioned above. I've been unable to reproduce the same with an android 4.1 device, only with two 2.3 devices.</p>
  
  <p>Googling around I found this:</p>
  
  <p><a href="http://androiddiscuss.com/1-android-discuss/42614.html" rel="nofollow noreferrer">http://androiddiscuss.com/1-android-discuss/42614.html</a></p>
  
  <p>suggesting the binder transaction buffer is somewhat exhausted. We use the MediaPlayer, InApp-Billing and Google Cloud Messages which use binding. I removed all of them and still get into this error. Maybe someone knows other hidden binder related stuff to check for?</p>