FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS excludes the entire application, not just activity

I have a notification that triggers an Activity. After a long press of the home button and selecting my application, I want to start my main activity again, and not this activity, which started with notifications. I tried FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS, but this removed my entire application from retentates, and this is not what I want to achieve. How can I get my application in regents, but the main action has begun?

Hello

+4
source share
2 answers

Ok, I found a solution to my problem. I started with a notification using FLAG_ACTIVITY_NEW_TASK . But it seems to me that this activity is launched only in its own task, if the affinity differs from the default proximity. So I had to add another affinity to the manifest.

And it seems that FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS does not perform (as documented) the exlucde Activity from the recents, but excludes the entire task (not the entire application) in which the action is launched from repeats. And since I did not specify another proximity, the activity that I wanted to exclude was launched in the same task (although I set FLAG_ACTIVITY_NEW_TASK ), and therefore my whole application (since it was executed in only one task) was excluded from my fathers.

Now I have set up another affinity for Activity that starts from Notification, and I start it with FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS . When I leave this action and hold the HOME button for a long time, I can select my application, and by default the task starts or is brought to the foreground.

If this is wrong, as I mentioned above, feel free to clean it ...

+12
source

I don’t understand what you want.

"How can I use my application in regents, but have the main action started?"

If you want to always run a single action with a long home click, you can define your activity as singleTask in the manifest.

Thus, when you select a shortcut by long pressing HOME, it will always show MAIN, singleTask . I say this because I used to use this behavior .; -)

I believe that using this, you can still start the activity from the notification using, say, Intent s.

In the activity tag:

  android:launchMode="singleTask" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 
+1
source

All Articles