Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly clear intent data from singleTop Activity?

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 issue 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.

like image 492
Jona Avatar asked Apr 19 '11 15:04

Jona


People also ask

How to finish the activity in android?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.

What is Flag activity clear top?

FLAG_ACTIVITY_CLEAR_TOP. If the activity being started is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it are destroyed and this intent is delivered to the resumed instance of the activity (now on top), through onNewIntent() ).

How do you pass an activity in intent?

The easiest way to do this would be to pass the session id to the signout activity in the Intent you're using to start the activity: Intent intent = new Intent(getBaseContext(), SignoutActivity. class); intent. putExtra("EXTRA_SESSION_ID", sessionId); startActivity(intent);

What is intent Flag_activity_new_task in Android?

launchMode — singleTask | flag — FLAG_ACTIVITY_NEW_TASK: If an Activity do not exist in an already created Task, then it starts the Activity in a new Task with Activity's new instance at the root of the Task's back stack, else the Task is brought forward with the Activity's last state restored and this Activity ...


1 Answers

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

like image 129
Jona Avatar answered Sep 21 '22 12:09

Jona