1

I am having a problem where the back stack is lost after you background an activity. I am already using "android:alwaysRetainTaskState="true" but that doesn't seem to fix my problem.

MainActivity->SomeActivity.

Send SomeActivity to background. Select SomeActivity from window list.

Back button does not go to MainActivity. It goes to the home screen.

How do I make it go back to MainActivity?

Intent i = new Intent(self, SomeActivity.class);
i.putExtra("launch", 1);
startActivity(i);

It will go back to MainActivity if the application is never background-ed.

bond
  • 1,054
  • 8
  • 15
  • Are you calling finish() on MainActivity when you are starting SomeActivity? How does your mainifest look like? And pls paste the intent you are using to start the SomeActivity. – VJ Vélan Solutions Dec 10 '13 at 14:20
  • Updated Original Post. No, I am not calling finish() on MainActivity. – bond Dec 10 '13 at 14:40
  • @misterbiscuit You should share some code in SomeActivity too, and how can you send SomeActivity to background? by press Home button? – ductran Dec 10 '13 at 14:53
  • @R4j yeah. Home button. – bond Dec 10 '13 at 14:54
  • Maybe this link helps you: http://stackoverflow.com/a/19791634/719212 I had faced with this problem before. – ductran Dec 10 '13 at 14:57
  • I am not closing the MainActivity however. I just setup a test app and it works properly there. Eventually I will figure out what is causing it and post. – bond Dec 10 '13 at 15:07
  • 1
    Worse than I thought. MainActivity is leaking because it is never destroyed in this scenario. – bond Dec 10 '13 at 15:32

1 Answers1

2
android:launchMode="singleInstance"

Is the root of the problem. While the back button does work if you never press the HOME button; the back stack will be cleared when the singleInstance activity is restarted.

bond
  • 1,054
  • 8
  • 15