Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude from recents an exported activity?

I have an app with an exported activity that can be invoked from other apps (Specifically the sharing action - android.intent.action.SEND)

How can an exported activity be excluded from recents?

I don't see a way to set the FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS flag, because it is invoked from the outside.

The reason I want to do this is because this intent becomes the last one in my activity stack, thus when clicking on the recents, a file is being re-shared instead of the main activity to pop up.

Note: android:launchMode="singleTask" solves the problem in a specific case, only where another activity is on top. BUT, this isn't an option because it disrupts the user task flow and doesn't work if there is no other app's activity at the root.

like image 450
AlikElzin-kilaka Avatar asked Mar 04 '13 13:03

AlikElzin-kilaka


People also ask

What are exported activities?

The exported attribute is used to define if an activity, service, or receiver in your app is accessible and can be launched from an external application. As a practical example, if you try to share a file you'll see a set of applications available.

What element does an activity use by default without having to add anything?

The default value is " true ". The <application> element has its own enabled attribute that applies to all application components, including activities. The <application> and <activity> attributes must both be " true " (as they both are by default) for the system to be able to instantiate the activity.

What is task affinity Android?

An affinity indicates which task an activity prefers to belong to. By default, all the activities from the same app have an affinity for each other. So, by default, all activities in the same app prefer to be in the same task. However, you can modify the default affinity for an activity.

Which attribute of the activity element is used to specify the class name of an activity?

The only required attribute for this element is android:name, which specifies the class name of the activity. You can also add attributes that define activity characteristics such as label, icon, or UI theme.


1 Answers

You can add the android:excludeFromRecents attirbute to your <activity> element in the manifest with a value of true:

<activity
    android:name="XYZ"
    android:excludeFromRecents="true">
like image 62
Raghav Sood Avatar answered Sep 23 '22 04:09

Raghav Sood