The target activity uses singleTop as launchMode. When it is launched from another application with the following code, it shows Fragment A, then user switches to fragment B. Then user switches to another app. When user enters the activity, it gets onNewIntent and navigates to Fragment A. But before Fragment A is shown, Fragment B is shown as a flicker. The flicker is seen with the following code-
private void launchActivity() {
Intent intent = new Intent();
intent.setAction(Constants.ACTION_MAIN);
intent.addCategory(Constants.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(Constants.PACKAGE_NAME,
Constants.ACTIVITY_CLASS_NAME));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
}
But the issue is not observed when intent.setAction(Constants.ACTION_MAIN) is removed and a random extra is added, which is nowhere used.
private void launchActivity() {
Intent intent = new Intent();
intent.setAction(Constants.ACTION_MAIN);
intent.addCategory(Constants.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(Constants.PACKAGE_NAME,
Constants.ACTIVITY_CLASS_NAME));
intent.putExtra("extra", 0);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
}
I could not find a logical explanation of this. Is fragment B is shown, as this remains in the buffer? Does this change clear the buffer?