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...
... 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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With