title: Android is force-killing my launcher on BT connect
body: <p>I have written a launcher-app for Android with Apache cordova. It's for a kiosk-like application and basically it's working fine.</p>
  
  <p>Unfortunatelly there is a problem:
  Under certain circumstances Android is force killing my app and immediately restarting it. - It takes about 3 seconds to load, where it shows a white screen. It starts completely new (onPause, onResume are not called). In the log I find:</p>
  
  <pre><code>V/WindowManager(  657): Changing focus from Window{42544288 u0 com.android.settings/com.android.settings.SubSettings} to Window{428ad610 u0 com.android.settings/com.android.settings.SubSettings} Callers=com.android.server.wm.WindowManagerService.addWindow:2665 com.android.server.wm.Session.addToDisplay:163 android.view.IWindowSession$Stub.onTransact:111 com.android.server.wm.Session.onTransact:126 
  I/WindowManager(  657): Gaining focus: Window{428ad610 u0 com.android.settings/com.android.settings.SubSettings}
  ...
  I/ActivityManager(  657): Force stopping com.myapp.name appid=10119 user=0: clear data
  I/ActivityManager(  657): Killing 2639:com.myapp.name/u0a119 (adj 7): stop com.myapp.name
  I/ActivityManager(  657):   Force finishing activity ActivityRecord{42542218 u0 com.myapp.name/.MainActivity t2}
  V/ActivityManager(  657): Broadcast: Intent { act=android.intent.action.PACKAGE_RESTARTED dat=package:com.myapp.name flg=0x10 (has extras) } ordered=false userid=0 callerApp=null
  V/ActivityManager(  657): Broadcast: Intent { act=android.intent.action.PACKAGE_DATA_CLEARED dat=package:com.myapp.name flg=0x10 (has extras) } ordered=false userid=0 callerApp=null
  I/NotificationService(  657): queryReplace=false
  I/ActivityManager(  657): Start proc com.android.documentsui for broadcast com.android.documentsui/.PackageReceiver: pid=2740 uid=10036 gids={50036}
  V/WindowManager(  657): Changing focus from Window{428ad610 u0 com.android.settings/com.android.settings.SubSettings EXITING} to Window{42544288 u0 com.android.settings/com.android.settings.SubSettings} Callers=com.android.server.wm.WindowManagerService.removeWindowLocked:2770 com.android.server.wm.WindowManagerService.removeWindow:2709 com.android.server.wm.Session.remove:182 android.view.IWindowSession$Stub.onTransact:197 
  ...
  I/WindowManager(  657): Gaining focus: Window{42544288 u0 com.android.settings/com.android.settings.SubSettings}
  I/WindowManager(  657): Losing focus: Window{428ad610 u0 com.android.settings/com.android.settings.SubSettings EXITING}
  D/DisplayManagerService(  657): Display listener for pid 2639 died.
  D/WifiService(  657): Client connection lost with reason: 4
  I/WindowState(  657): WIN DEATH: Window{424b0f20 u0 com.myapp.name/com.myapp.name.MainActivity}
  W/WindowManager(  657): Force-removing child win Window{424c4168 u0 SurfaceView} from container Window{424b0f20 u0 com.myapp.name/com.myapp.name.MainActivity}
  W/WindowManager(  657): Failed looking up window
  W/WindowManager(  657): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@427d8618 does not exist
  W/WindowManager(  657):   at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8571)
  W/WindowManager(  657):   at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8562)
  W/WindowManager(  657):   at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1060)
  W/WindowManager(  657):   at android.os.BinderProxy.sendDeathNotice(Binder.java:496)
  W/WindowManager(  657):   at dalvik.system.NativeStart.run(Native Method)
  I/WindowState(  657): WIN DEATH: null
  V/InputMethodManagerService(  657): windowGainedFocus: android.os.BinderProxy@4284cbd0 controlFlags=#0 softInputMode=#10 windowFlags=#1810100
  W/InputMethodManagerService(  657): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@42621308 attribute=null, token = android.os.BinderProxy@41f7d370
  ...
  V/SettingsProvider(  657): call(system:anr_debugging_mechanism) for 0
  W/ContextImpl( 2336): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1219 android.content.ContextWrapper.sendBroadcast:365 com.android.settings.applications.InstalledAppDetails.processClearMsg:1133 com.android.settings.applications.InstalledAppDetails.access$000:105 com.android.settings.applications.InstalledAppDetails$1.handleMessage:223 
  </code></pre>
  
  <p><strong>The circumstances when it happens:</strong></p>
  
  <ul>
  <li>It happens after several hours of uptime</li>
  <li>It happens <strong>everytime</strong> you connect a Bluetooth Remote control. (It is paired already). After some minutes of idle the remote control disconnects to save power. As soon as you reconnect it (by pressing a button), the app crashes and restarts.</li>
  </ul>
  
  <p><strong>What I tried so far without luck:</strong></p>
  
  <ul>
  <li>Install the app as a "normal" app (not a launcher)</li>
  <li>Uninstall every cordova plugin</li>
  </ul>
  
  <p><strong>Devices, where the error occurs:</strong> </p>
  
  <ul>
  <li>Android 4.4.2 tablet ("no-name" product) - The error is present</li>
  <li>Android 5.1 tablet ("no-name" product) - The error is present</li>
  <li>Android 5.1.1 phone (Samsung xCover) - No problem!!</li>
  <li>Android 4.4.2 phone (Samsung GALAXY S III Neo) - No problem!!</li>
  </ul>
  
  <p>So why is the Android on the tablets killing my app? Is it because they have cheap hardware, or because the Android versions are older? <strong>How can I prevent this bug?</strong> </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I found out, that the problem is not programming-related, because this issue occurs on <strong>every app</strong>. That's why I posted another question on <a href="https://android.stackexchange.com/questions/146473/every-app-crashes-if-you-connect-a-bt-input-device">Android-Enthusiasts</a></p>