Reset activity stack without starting a new activity

I have a broadcast receiver triggered by an emergency event that checks if the application is working (user is inactive). Now I would like to reset the activity stack and bring the application to the first activity by default.

But if I do something like this:

Intent intent = new Intent(context, StartUp.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); 

then my application comes to the fore.

I would like to do this quietly so that the user is not disturbed by my application (as he is doing something else).

So my question is how to clear the activity stack without starting the activity?

+4
source share
2 answers

Checking that any of your actions is in the foreground seems to be covered here , although I have not tried it. Then, if you want to complete the entire application, just do:

 System.runFinalizersOnExit(true); System.exit(0); 

And you're done. Hope this helps you.

+3
source

At the top of my head, why not save the state, for example, general settings, and when the user starts your application again, you may find that it needs to be cleaned and restarted. That is, use the concept of a delay reset stack. Are there probably other consequences, such as the SharedPreferences in BroadcastReceiver, that don't seem to update? just to give an idea.

0
source

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


All Articles