`The LauncherActivity is the first screen in Homescreen. I am tyring to understand if singleTop or singleTask would be the right launchmode.
The idea is to avoid creating muktiple acitivty instances in all transitions to Homescreen.
The activity configuration in Manifest is –
<activity
android:name=".ui.LauncherActivity"
android:clearTaskOnLaunch="true"
android:exported="true"
android:stateNotNeeded="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER_APP" />
</intent-filter>
</activity>
The activity can be triggered only from a non-acitivty application, which belongs to a different package from LauncherActivity. It is launched like below-
private void startHomeActivity() {
Intent intent = new Intent();
intent.setAction(Constants.ACTION_MAIN);
intent.addCategory(Constants.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(Constants.HOME_PACKAGE_NAME,
Constants.HOME_ACTIVITY_CLASS_NAME));
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
}
Observation:
Currently singleTop is set as launchmode for the LauncherActivity. Please note that, AppDrawerActivity is another acitivty, which belong to Homescreen application package.
The transition is done as below-
- Reboot the system, current screen is Homescreen(LauncherActivity).
- Switch to AppDrawerActivity
- Switch to HVAC application from AppDrawerActivity
at this point the activity dump shows the stack as below. Here, we can see that in task#1200003, AppDrawerActivity is on the top of the stack.
Task display areas in top down Z order: TaskDisplayArea DefaultTaskDisplayArea mPreferredTopFocusableRootTask=Task{82141e #1200004 type=standard A=1210072:com.apps.hvac U=12 visible=true visibleRequested=true mode=fullscreen translucent=false sz=1} mLastFocusedRootTask=Task{82141e #1200004 type=standard A=1210072:com.apps.hvac U=12 visible=true visibleRequested=true mode=fullscreen translucent=false sz=1} Application tokens in top down Z order: * Task{82141e #1200004 type=standard A=1210072:com.apps.hvac U=12 visible=true visibleRequested=true mode=fullscreen translucent=false sz=1} bounds=[0,0][1280,720] * ActivityRecord{63ba8ca u12 com.apps.hvac/.ui.HvacLandingActivity t1200004} * Task{57a2911 #1 type=home ?? U=0 visible=false visibleRequested=false mode=fullscreen translucent=true sz=2} bounds=[0,0][1280,720] * Task{4bd5acd #1200003 type=home A=1201000:com.apps.homescreen U=12 rootTaskId=1 visible=false visibleRequested=false mode=fullscreen translucent=true sz=2} bounds=[0,0][1280,720] * ActivityRecord{34c92b u12 com.apps.homescreen/.ui.AppDrawerActivity t1200003} * ActivityRecord{d1d210e u12 com.apps.homescreen/.ui.LauncherActivity t1200003} * Task{4089178 #2 type=home A=10132:com.android.car.provision U=0 rootTaskId=1 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1} bounds=[0,0][1280,720] * ActivityRecord{6be6283 u0 com.android.car.provision/.DefaultActivity t2}
The we click on Home button, which is handled in a different non-acitivty application. Now the stack looks as below.
Task display areas in top down Z order: TaskDisplayArea DefaultTaskDisplayArea mPreferredTopFocusableRootTask=Task{57a2911 #1 type=home ?? U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=2} mLastFocusedRootTask=Task{57a2911 #1 type=home ?? U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=2} Application tokens in top down Z order: * Task{57a2911 #1 type=home ?? U=0 visible=true visibleRequested=true mode=fullscreen translucent=false sz=2} bounds=[0,0][1280,720] * Task{4bd5acd #1200003 type=home A=1201000:com.apps.homescreen U=12 rootTaskId=1 visible=true visibleRequested=true mode=fullscreen translucent=false sz=1} bounds=[0,0][1280,720] * ActivityRecord{d1d210e u12 com.apps.homescreen/.ui.LauncherActivity t1200003} * Task{4089178 #2 type=home A=10132:com.android.car.provision U=0 rootTaskId=1 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1} bounds=[0,0][1280,720] * ActivityRecord{6be6283 u0 com.android.car.provision/.DefaultActivity t2} * Task{82141e #1200004 type=standard A=1210072:com.apps.hvac U=12 visible=false visibleRequested=false mode=fullscreen translucent=true sz=1} bounds=[0,0][1280,720] * ActivityRecord{63ba8ca u12 com.apps.hvac/.ui.HvacLandingActivity t1200004}
**Could anyone please help to understand these points?
-
As per the document, when a singleTop acitivty is started, if it is not at the top of the task, it should be recreated. In this case,
AppDrawerActivity was at the top of task. But still why the previous instance of LauncherActivity was reused instead of recreating it? -
In this case which launchmode would be ideal in between singleTop and singleTask?**
`