How to return to any activity in the action stack?

Does anyone know if it is possible that an action is removed from the action stack if there is no memory on the device? I have activity A, which calls a web browser and a webpage, then calls activity B, which does something, and then should return to activity A. I use this intent with flags.

Intent intent = new Intent(this, acticityToReturnTo.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); 

.. to remove the activity of the web browser and activity B from the action stack and return to activity A, but this will not work. Its always a new instance of activity A, which is created instead of resuming an existing activity by an instance. I don't want to use the single instance flag for activity A, but this is the only solution that currently works for me .. (Im for Android 1.6)

Maybe there is another solution to do what I want?

+4
source share
4 answers

Just try using

startActivityForResult (intent);

instead

startActivity (intent);

+2
source

I would rather think about it from the point of view of why its problem is to restart activity A, given that the action of A or B in this case can be killed at any time in your operation.

Of course, it would be better to make sure that you can return to Activity A, regardless of whether you either restarted it or re-created it from scratch, as there is no guarantee that this will not happen.

+1
source

If navigation is always A-> B-> A, you can simply call finish() in action B and return to activity A

0
source

Is there a browser and activity A in the same task? You can verify this by entering adb shell dumpsys activity in the console.

0
source

Source: https://habr.com/ru/post/1335074/


All Articles