Skip to main content

Posts

Showing posts with the label lifecycle

Android lifecycle weirdness with singleTop and foreground service?

Here's the scenario: Start Activity A Activity A starts service S Service S runs in foreground mode and shows up a notification which when pressed takes the user to Activity B (which has launchMode="singleTop") Activity B shows up Press HOME Go into DDMS and kill your application process to simulate that your app died (press red STOP button) Android will say "Rescheduling crashed service in 5000ms" (sometimes longer) Service S restarts and notification is shown. Press the notification icon when the service restarts... ...at this time, Android will recover both Activities A and B due to the fact the process ended unexpectedly. But despite the fact Activity B is singleTop android will spawn it AGAIN because the user clicked on the notification. This results into having A -> B -> B on the activity stack. Pressing back will take you again onto the first recovered instance of Activity B. Can someone from the Android tea