1

I have an application with the following flow:

Loading activity -> activity 1 -> activity 2

where the loading activity is closed using finish() after launching activity 1.

When clicking the home button and then relaunching it after a while (seems to be 30 minutes or more), I was expecting one of the following behaviors:

  1. The activity is still alive - continue from activity 2.
  2. The activity was killed - restart from the loading activity.

However, what happens is that the app starts from activity 1. I'm assuming this means that the activity task was cleared, because if the loading activity is not being closed, the app starts there (but I do need to close it).

Is that assumption correct or is there a different explanation behind this? What can be done in order to have the app relaunch from the loading activity in this scenario?

Amit
  • 1,174
  • 2
  • 15
  • 22
  • I **think** this SO post will answer your question: http://stackoverflow.com/questions/7008162/my-app-killed-by-android-system-when-it-running-in-background – Salil Pandit Jul 13 '12 at 22:49
  • How are you launching activity 2? Do you call finish in activity 1 as well? – TJ Thind Jul 13 '12 at 22:55
  • @Salil Pandit - that question does not solve the problem for me. I don't mind the app being killed after a while, but I do mind the described behavior. – Amit Jul 13 '12 at 23:07
  • @TJ Thind - I start activity 2 using `startActivity` from activity 1. I'm not calling `finish` in activity 1. – Amit Jul 13 '12 at 23:08
  • I'm guessing since you're not calling finish in Activity 1 you're expecting to be able to keep it in the back stack to return to from activity 2? – TJ Thind Jul 13 '12 at 23:32
  • No, I'm expecting the activity to continue from activity 2, where it was before putting it in the background (expected behavior #1 in my question), but it doesn't (starting from activity 1). – Amit Jul 13 '12 at 23:38
  • Something else is going on. Your expectation is correct. Either it should show Activity2 (return the user to where he was) or start with your loading activity (if Android cleared the task stack). Can you post the logcat when this happens? There is definitely something else going on. – David Wasser Aug 28 '12 at 16:54

1 Answers1

0

You could try adding FLAG_ACTIVITY_NO_HISTORY flag to the intent when launching activity 1 from the loading activity.

    Intent intent = new Intent(this, A.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent);

Once activity 1 is navigated away from it's finished. If that's not the appropriate flag there are a number of others to choose from which can manipulate the history stack.

TJ Thind
  • 784
  • 5
  • 17
  • That's not the desired behavior - I do want activity 1 to still be alive (being able to return there from activity 2 by clicking back). I just want the application to either return to activity 2 (or any other activity I was in - there can be other ones), or start from the very beginning (the loading activity). – Amit Jul 14 '12 at 11:06