Wednesday, 21 April 2021

Reopen App After Kill, Opens Previous Activity

My app history is normal; I am not using any fancy flags or anything when I am launching intents. Only sequential, single-task launched activities. If I go Home, and then use a task killer to kill my app, the next time I open the app it starts up at the last activity that I was on before the kill rather than the declared Main activity. Additionally, if I then hit Back to exit the app and reopen it again, I get whatever Activity was open before the one that I had previously opened before the kill.

Something like this:

A = Main Activity; B = Some Other Activity; C = Some Other Activity

  • Open app - A
  • Open B - B
  • Open C - C
  • Kill app with task killer
  • Open app - C
  • Back button - Device home
  • Open app - B
  • Back button - Device home
  • Open app - A

I would expect that the backstack would not be remembered after the task kill. I would expect that the app would always start from the declared Main activity unless it is already running in the background. (which is not the case here since the kill is being utilized) Both of these things seem not to be happening however and I do not know why.

I tried putting in some code to set an "initialized" boolean in my Application class on A's onCreate and then to check against it in B and C's onCreate. The idea there was to launch A's intent with the NEW_TASK and CLEAR_TOP flags to try to detect and correct the scenario, but it still exhibited the same exact behavior except that it would also put A on top of whatever was leftover. So instead of starting the app into B, it would start the app into BA.

Based on everything I have read about activity lifecycle and OS killing of apps, this is impossible, but it is definitely happening on all of my test devices. Does anyone have any ideas as to what might be causing this odd behavior?



from Reopen App After Kill, Opens Previous Activity

No comments:

Post a Comment