Reputation: 1550
I have an activity that exists in the manifest like so:
<activity android:name=".activity.Main" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="asdf.com"/>
</intent-filter>
</activity>
So that intercept and handle links to http://asdf.com. After I handle one of these intents, I back out of my main activity.
If I go back to my app using the task manager, it will use the same intent, with the same data that I have already handled. Is there way that I can essentially clear or replace this intent, so that it is not reused by the task manager? If I launch normally, by clicking on the app instead of using the task manager, it does not reuse the data.
Thanks
Upvotes: 3
Views: 1938
Reputation: 1550
My problem case is when the activity is launched from the home button, so this seems to be a working solution:
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
//handle intent
};
That flag is true if launched from the task manager, in which case I can ignore the intent data. This will likely not work for some other cases.
Upvotes: 2
Reputation: 6366
When you reenter an app that has been set with the "singleTask" launch mode, it does not create a new instance of the the activity if it already exists, instead it reuses up the old activity and brings it to the top of the stack. You must overwrite the onNewIntent() method of your activity to handle whatever actions you may need. When you bring an activity to the front of the stack this onNewIntent() is called an you will need to reset the data in that function.
More info on Tasks and Back Stack here.
Upvotes: 1