Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to Intent.FLAG_ACTIVITY_CLEAR_TASK

I have two apps App-B launches App-A. If the user starts App B from inside App A I call finish on App-A so I have no problem.

If the user goes straight to App B from the Application drawer or long pressing home button then I implement the below which clears the task in App A first before applying all the extras. This has the desired affect but only works on API 11. On lower APIs the new task in APP-A will not change and extras putExtra will have no effect. Any alternative to FLAG_ACTIVITY_CLEAR_TASK? for API <=10?

        Intent i = new Intent("com.App-A");     i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 

Thanks

Jason

like image 517
Jason Smith Avatar asked Jun 19 '12 09:06

Jason Smith


People also ask

What is Flag_activity_clear_task?

flag — FLAG_ACTIVITY_CLEAR_TASK: This clears any existing task that would be associated with the Activity before the Activity is started. This Activity then becomes the new root of the task and old Activities are finished.

What is java intent?

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke activity, broadcast receivers etc.

What is Flag_activity_new_task?

When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in. See FLAG_ACTIVITY_MULTIPLE_TASK for a flag to disable this behavior.

What is getIntent in Android?

you can retrieve this data using getIntent in the new activity: Intent intent = getIntent(); intent. getExtra("someKey") ... So, it's not for handling returning data from an Activity, like onActivityResult, but it's for passing data to a new Activity. Follow this answer to receive notifications.


1 Answers

The new IntentCompat should've helped on that, but apparently the flag is ignored for API lower than 11.

To use IntentCompat do following:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK); 
like image 56
Warpzit Avatar answered Oct 08 '22 21:10

Warpzit