开发者

How to properly clear intent data from singleTop Activity?

开发者 https://www.devze.com 2023-02-26 18:54 出处:网络
Scenario is: Activity with singleTop declared at the manifest. This activity is called with some extras.I\'m able to clear the intent data and be able to flip screen and such without the original inte

Scenario is: Activity with singleTop declared at the manifest. This activity is called with some extras. I'm able to clear the intent data and be able to flip screen and such without the original intent being called...

The i开发者_Python百科ssue is that when the activity is killed by the system and the user goes back to this activity it gets restarted using the original intent used to create the activity.

How do I remove this? I tried starting the same activity from within with a new Intent but no luck... I have also used various flags.


Well turns out that there isn't a proper way to clear intent data from the ActivityManager. The only way around this bug is to keep a flag state for when extras have been cleared. Please see the following post about keeping a flag. https://groups.google.com/forum/#!topic/android-developers/vrLdM5mKeoY


I'm sending pending intents as alarms and I could receive differents alarms when my app is launched so the flag state doesn't suit me.

I did like this :

I'm sending intents with a id, for example intent.setAction("MyIntent"+System.getCurrentTimeinMillis); storing this key as a reference in BD or shared prefs.

When you receive the intent on newIntent you ask the bd or shared prefs is the intent.getAction() is there and after that you clear the reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号