MMasmoudi
MMasmoudi

Reputation: 550

Activities back stack seems to be lost

I have 2 activities: A and B
In B, I have a back arrow to go back to A by calling "finish()" method.
It works fine, except when the following is done:

Any help please ?

Upvotes: 2

Views: 502

Answers (4)

kartik malik
kartik malik

Reputation: 312

Make Activity A as parent Activity of Activity B in your manifest file. Works for you.

Upvotes: 0

Bivin OC
Bivin OC

Reputation: 131

Set flag in onStop () method to know and write condition onBackPress () condition to navigate to A according to the Flag value changes

Upvotes: 0

MMasmoudi
MMasmoudi

Reputation: 550

I figured out how to solve this:
As @Karthikeyan mentioned in its comment, setting launchMode to "singleInstance" is cause of the problem. I changed it to "singleTask" and it worked fine.
In fact, according to the google doc stated in https://developer.android.com/guide/components/activities/tasks-and-back-stack,

"singleInstance". Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance.

So logically, with "singleInstance", the activity when restored from the background had no other activity in the same back stack, and thus, calling finish() would simply finish the activity without restoring whatsoever (the very first activity is in the background and in another separate task)

Upvotes: 1

Karthikeyan
Karthikeyan

Reputation: 296

Do not keep activities make sure that this option is not enabled in your device's developer settings.

Upvotes: 0

Related Questions