1

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:

  1. Disabling orientation changes in case shaking the device causes config changes.
  2. Disabling swipeToDismisson the Wear activity in case a tap was misinterpreted as a fast swipe to close.
  3. Overriding onLowMemory() with breakpoints to check if it is a resource issue.
  4. Overriding onFinish() with breakpoints in case of an unintentionall call to finish()

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?

Community
  • 1
  • 1
Morne
  • 814
  • 6
  • 14
  • 1
    By seeing logcat I think there is something wrong with your onStop method ... – Umair Sep 04 '14 at 06:47
  • No, my onStop just calls through to super.onStop(). It is just there to place a break point and catch the point where the activity is stopped to obtain a stack trace. There is no exception being thrown anywhere. – Morne Sep 04 '14 at 07:25
  • Isn't there any exception thrown? I miss it in your Logcat ... – Anthea Sep 04 '14 at 07:30
  • post the full logcat, that is just a part of it. there should be an exception – Ker p pag Sep 04 '14 at 08:10
  • What is line `at myRandomApp.WearActivity.onStop(WearActivity.java:76)` ? – EpicPandaForce Sep 04 '14 at 08:10
  • All, please don't get stuck on looking for an exception. As already mentioned in both my post and the comments, there is NO EXCEPTION being thrown, there is a breakpoint set by me on line 76 which just calls `super.onStop()`. My original question was to find a way to figure out WHY my activity is being stopped (cleanly). – Morne Sep 04 '14 at 09:19

1 Answers1

0

I don't have an answer for my original question, but I have a workaround for the symptoms caused by it. Rather than starting my app as a full screen activity, I instead create a notification in the context stream with an action to go fullscreen. The notification is persistent, so even when other cards enter the stream, they don't cause my task to quit.

Iv'e filed a bug for this issue at https://code.google.com/p/android/issues/detail?id=75918&thanks=75918&ts=1410235765

The original question remains open, but I suspect it has no answer...

Morne
  • 814
  • 6
  • 14
  • Do incoming text messages also cause the problem for you? Or it is just the pedometer notification popping up? – Wayne Piekarski Sep 16 '14 at 20:07
  • It happened for all new cards, not just the pedometer. Easily reproducible by sending demo cards from the Android Wear app on the handheld. It is worth noting that I create my notification with a custom layout set with `setDisplayIntent()` in order to start an activity associated with my application and keep the task alive. – Morne Sep 18 '14 at 02:29