Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android is force-killing my launcher on BT connect

I have written a launcher-app for Android with Apache cordova. It's for a kiosk-like application and basically it's working fine.

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:

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 

The circumstances when it happens:

  • It happens after several hours of uptime
  • It happens everytime 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.

What I tried so far without luck:

  • Install the app as a "normal" app (not a launcher)
  • Uninstall every cordova plugin

Devices, where the error occurs:

  • Android 4.4.2 tablet ("no-name" product) - The error is present
  • Android 5.1 tablet ("no-name" product) - The error is present
  • Android 5.1.1 phone (Samsung xCover) - No problem!!
  • Android 4.4.2 phone (Samsung GALAXY S III Neo) - No problem!!

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? How can I prevent this bug?

UPDATE

I found out, that the problem is not programming-related, because this issue occurs on every app. That's why I posted another question on Android-Enthusiasts

like image 824
Michael B Avatar asked Jun 01 '16 07:06

Michael B


1 Answers

The problem was caused by changes to the system configuration in runtime. By default activities will not handle those, but will just restart.

See https://developer.android.com/guide/topics/resources/runtime-changes.html

Cordova adds handlers for orientation, keyboardHidden, keyboard, screenSize and locale by default.

In order to fix our problem we just needed to add to handle the config change for navigation to our activity like this:

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|navigation">
like image 105
IngoAlbers Avatar answered Sep 28 '22 10:09

IngoAlbers