How to clear intent data from SingleTop Activity?

Scenario: Activity with singleTop is declared in the manifest. This activity is called some additional features. I can clear the intent data and be able to flip the screen, etc. Without calling the original intention ...

The problem is that when an activity is killed by the system and the user returns to this action, it restarts using the original intent used to create the activity.

How to remove this? I tried to start the same activity from the inside with a new intention, but no luck ... I also used different flags.

+6
source share
2 answers

Well, it turns out that there is no clear way to clear intent data from an ActivityManager. The only way to avoid this error is to keep the flag state when additional functions have been cleared. Please see the next post about saving the flag. https://groups.google.com/forum/#!topic/android-developers/vrLdM5mKeoY

+8
source

I send pending intentions as alarms, and I can receive different alarms when the application starts, so the state of the flag does not suit me.

I like it:

I send intentions with an identifier, for example, int.setAction ("MyIntent" + System.getCurrentTimeinMillis); keeping this key as a reference in BD or general privileges.

When you get the newIntent intent, you ask that bd or shared prefs is the .getAction () intent, and after that you clear the link.

+1
source

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


All Articles