Reputation: 6065
https://developer.android.com/guide/topics/manifest/activity-element.html
android:alwaysRetainTaskState
Whether or not the state of the task that the activity is in will always be maintained by the system — "true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain situations...This attribute is meaningful only for the root activity of a task; it's ignored for all other activities.
So what does root activity mean exactly?
Does root activity mean
"Activity that is defined with android.intent.action.MAIN
and android.intent.category.LAUNCHER
"
or just
"whatever activity that happens to be at the bottom of the back stack at this exact moment"
Upvotes: 1
Views: 4970
Reputation: 301
To build on Zohra's answers, you can change the MAIN and LAUNCHER activity in the AndroidManifest.xml. To apply this to a particular activity, define them in between an intent filter as such:
<activity android:name=".StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0
Reputation: 5302
In general Yes, the activity that is defined with android.intent.action.MAIN
and android.intent.category.LAUNCHER
will be the root activity of the task stack.
But with few intent flags we can make any any activity as root activity.
e.g. I have three activities in my stack A->B->C and now I want to launch activity D as a root activity by setting these intent flags
FLAG_ACTIVITY_CLEAR_TASK|FLAG_ACTIVITY_NEW_TASK
activity D will be root activity.
FLAG_ACTIVITY_CLEAR_TASK
:
If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.
Upvotes: 3
Reputation: 16
In android when you launch an app Main or root activity is first activity to be executed. For root activity it is compulsory to have android.intent.action.MAIN and android.intent.category.LAUNCHER intent filters.
Upvotes: 0