Activities back stack seems to be lost

45
December 06, 2018, at 4:50 PM

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:

  • I go to B
  • I put my app in background
  • I restore my app from "recent apps"
  • I press the back arrow, and then, the app is finished instead of going back to activity A.

Any help please ?

Answer 1

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

Answer 2

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)

Answer 3

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

READ ALSO
how to get fixed header and scrolling list item on nativescirpt radlistview

how to get fixed header and scrolling list item on nativescirpt radlistview

my sample code herethe problem is when i scroll the list header will go off, which should be fixed in position

32
Android navigation architecture testing

Android navigation architecture testing

please help me to test android navigation architecture component by using androidarch

21
How to unregister multiple Broadcast receiver which are in different classes at a time?

How to unregister multiple Broadcast receiver which are in different classes at a time?

i want to unregister some broadcast receivers with single clickhere is the flow

44