Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does excludeFromRecents remove all activities?

My app has two entry points (MainActivity and FromNotificationActivity).

I want MainActivity to appear in recent tasks, but not FromNotificationActivity)

With nothing declared in the manifest, if I do...

  • MainActivity
  • Back
  • FromNotificationActivity
  • Back

... I find FromNotificationActivity listed in recent tasks

If I add android:excludeFromRecents="true" to FromNotificationActivity in the manifest and repeat the same sequence, I find nothing in the recent lists.

What incantations must I invoke such that after the above sequence of steps, I get MainActivity in the recent list.

like image 941
pinoyyid Avatar asked May 17 '14 15:05

pinoyyid


People also ask

What is android excludeFromRecents?

android:excludeFromRecents ensures the task is not listed in the recent apps. That is the reason, when android:excludeFromRecents is set to true for FromNotificationActivity , MainActivity disappers from history. Solution: Use android:taskAffinity to specify different tasks for both the activities.

What is the use of activity tag?

activity is the subelement of application and represents an activity that must be defined in the AndroidManifest. xml file. It has many attributes such as label, name, theme, launchMode etc. android:label represents a label i.e. displayed on the screen.


1 Answers

By default, all the activities of an application have the same affinity. Activities with same affinity conceptually belong to the same task. Hence in this case both MainActivity and FromNotificationActivity belong to the same task. android:excludeFromRecents ensures the task is not listed in the recent apps. That is the reason, when android:excludeFromRecents is set to true for FromNotificationActivity, MainActivity disappers from history.

Solution: Use android:taskAffinity to specify different tasks for both the activities. Use android:excludeFromRecents for FromNotificationActivity if that task should not be shown in history at all.

<activity        android:name="com.example.MainActivity"     android:label="@string/app_name"     android:taskAffinity=".MainActivity" >         <intent-filter>             <action android:name="android.intent.action.MAIN" />             <category android:name="android.intent.category.LAUNCHER" />         </intent-filter> </activity>   <activity android:name="com.example.FromNotificationActivity"     android:label="@string/notification_name"     android:taskAffinity=".NotificationActivity"     android:excludeFromRecents="true">         <intent-filter>             <action android:name="android.intent.action.MAIN" />             <category android:name="android.intent.category.LAUNCHER" />         </intent-filter> </activity>  
like image 104
Manish Mulimani Avatar answered Oct 12 '22 22:10

Manish Mulimani