Android is force-killing my launcher on BT connect
Asked Answered
P

5

8

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

Pinero answered 1/6, 2016 at 7:43 Comment(10)
Though i m not an expert in Android, looking at the log i feel the key lies in the following lines- "java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@427d8618 does not exist" This error usually happens when you try to invoke a system API that is not available on your target device. That's why as you said this issue is device dependent. Also this issue causes the application to reboot as you said. All you need to figure out is "what is that API call which crashes your app". Hope it makes sense.Lindner
@IngoAlbers Though i m not an expert in Android, looking at the log i feel the key lies in the following lines- "java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@427d8618 does not exist" This error usually happens when you try to invoke a system API that is not available on your target device. That's why as you said this issue is device dependent. Also this issue causes the application to reboot as you said. All you need to figure out is "what is that API call which crashes your app". Hope it makes sense.Lindner
Thank you for your comment. The problem is, that I don't invoke any system API call. The system does it itself. Maybe I can change this in some system-configuration file? (root is available), but I don't know where to look and what to change.Pinero
You have mentioned that this issue happens every time when you are connecting to Bluetooth Remote Control. So i would look in those lines to figure outLindner
One more interesting thing i noted in your post is that this crash happens only in no-name product. So i believe no-name could just be causing the issue as during bluetooth pairing, internally BluetoothDevice.getName() may be returning null resulting in the crash.I strongly believe this is causing the issue and suggest you to look at this link for some help - #26291140 Keep me postedLindner
@IngoAlbers Did you had a chance to look at this comment? was it useful?Lindner
@IngoAlbers l Any update on this?Lindner
@Lindner Sadly I don't work on this project any more. As far as I know Michael didn't solve this issue yet. He will update here soon. Thank you for the comments so far. Certainly gave some ideas.Perreault
@MichaelB Any luck Michael? Did the answer helped?Lindner
@Perreault Thanks for the bounty. Really feel motivated. Happy coding. CheersLindner
P
1

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">
Perreault answered 1/7, 2016 at 12:43 Comment(0)
A
0

In the devices that are crashing, for some reason do you have the developer option: Do not keep activities marked.

Do you use cordova plugins that changes activities?

It look like for some reason an activity is being destroyed, here you can find some information:

https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#when-can-this-happen

Areopagite answered 3/6, 2016 at 18:26 Comment(1)
Thank you! "Do not keep activities" is not set. Also I have removed every cordova plugin and tested it with a fresh new Cordova-app. The error is also present there.Pinero
H
0

This the true with all apps. Any app that has gone to background or is not being used for some time, the virtual engine sets it to lower priority and when it needs memory or any other resource, it kills the app.

You can't avoid it. What you can do is to restart at the same place where it was killed using onSaveInsanceState()and onRestoreInstanceState():

onSaveInstanceState () and onRestoreInstanceState ()

The other option is to have a service attached to your app. This way your app doesn't get killed:

How can we prevent a Service from being killed by OS?

Hardman answered 8/6, 2016 at 8:37 Comment(1)
This could be a genric solution. But i dont think it addresses the specific issue that the user is stuck with.Lindner
L
0

Though i m not an expert in Android, looking at the log i feel the key lies in the following lines:

"java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@427d8618 does not exist"

This error usually happens when you try to invoke a system API that is not available on your target device. That's why as you said this issue is device dependent. Also this issue causes the application to reboot as you said. All you need to figure out is "what is that API call which crashes your app"

One more interesting thing i noted in your post is that this crash happens only in no-name product. So I believe no-name could just be causing the issue as during bluetooth pairing, internally BluetoothDevice.getName() may be returning null resulting in the crash.I strongly believe this is causing the issue and suggest you to look at this link for some help.

Lindner answered 9/6, 2016 at 13:39 Comment(0)
P
0

Its not tablet or mobile problem. I suspect Don't Keep activities option(Developer options)is enabled in Your tablet. Please check that.

Android 4.4.2 tablet ("no-name" product) - The error is present

Android 5.1 tablet ("no-name" product) - The error is present

Penthea answered 9/6, 2016 at 15:11 Comment(1)
Thank you! Unfortunately this is not the case - the option is not set.Pinero

© 2022 - 2024 — McMap. All rights reserved.