I have a single activity with a couple of fragments that is being stopped randomly and I'm trying to figure out the cause. Similar issue to this (Why is my android activity being stopped?) but unrelated answer.
The activity is running on Android Wear, with accelerometer data being collected. It only stops if I also interact with the device while moving it, like tapping the screen. I've tried:
- Disabling orientation changes in case shaking the device causes config changes.
- Disabling
swipeToDismiss
on the Wear activity in case a tap was misinterpreted as a fast swipe to close. - Overriding
onLowMemory()
with breakpoints to check if it is a resource issue. - Overriding
onFinish()
with breakpoints in case of an unintentionall call tofinish()
The activity is started from a service with
Intent startIntent = new Intent( this, WearActivity.class );
startIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity( startIntent );
with the activity set to android:launchMode="singleTask"
, but there is only one start request.
I've run out of ideas. Is there any way to determine who is sending the stop message? Below is a complete stack trace, the activity is stopped by receiving the STOP_ACTIVITY_HIDE
system message in ActivityThread.handleMessage()
:
at myRandomApp.WearActivity.onStop(WearActivity.java:76)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1212)
at android.app.Activity.performStop(Activity.java:5387)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3196)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3245)
at android.app.ActivityThread.access$1100(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Method.java:-1)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(NativeStart.java:-1)
EDIT:
In response to some comments, the above stack trace was not generated by an exception being thrown. It is just where I hit a breakpoint to see the history of calls leading up to the app being stopped. The app exits cleanly, I'm trying to figure out why it wants to quit at all.
UPDATE: I've finally found the culprit. Invariably, before my app shuts down, I get this a few moments earlier in the log output:
I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.google.android.wearable.app/com.google.android.clockwork.home.HomeActivity (has extras)}
It appears moving the watch about increases the pedometer step count, which causes a new info card to be shown on the home screen of the watch. This card interrupts my full screen activity and closes it. Does anyone know of a way to prevent that? It feels like a Wear bug, I'm not sure other apps should be able to interrupt a running foreground application like that.
I've found the reason why my app shuts down, but only due to a lucky bit of info sent to the log. I'm still looking for an answer to my original question, for a general way to determine the reason for the Android system stopping apps. Maybe that is just not possible?