How to use activity over stack

My application has one write action called "Main". In β€œMain” I call one of the three other actions A, B or C (based on preference), and then immediately exit / end β€œMain”, so only A, B or C are active.

I also have a constant notification in the notification panel that users can pull out (at any time) in order to conveniently restart the application (calls with the Home component).

The problem is that if my application is already running and the users pull out the notification and restart, I get A or B or C working on top of the previous action (also A or B or C). How can I avoid this (i.e. reuse activity over stack)?

I tried Intent.FLAG_ACTIVITY_ * and nothing works. I tried launchModes
in the manifesto, and that didn't work either. Any ideas? Any help appreciated .... jh

+4
source share
1 answer

I found a way to do this that does what I want (although I am still testing it) ...

In the Android manifest for actions A, B, and C, I added the following line:

Android: launchMode = "singleTask"

This led to the reuse of activities A, B or C, if they were already at the top of the stack so that they did not restart on top of themselves (which required double-pressing the BACK button to exit the task).

+5
source

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


All Articles