SettingsLandingActivity holds multiple fragments and handles the transition in between them using NavController. When user enters the activity, it shows SettingsLandingFragment, as it is the default fragment.
Then user clicks on GeneralSettings shortcut, so it triggers an intent for GeneralSettingsFragment, it again uses the following code to switch to GeneralSettingsFragment. So, GeneralSettingsFragment is resumed and SettingLandingFragment gets onViewDestroyed.
Then user directly switches to another activity, GeneralSettingsFragment gets onPause. Then user clicks on Settings button, then the sequence of events is-
GeneralSettingsFragment gets onStart.
SettingsLandingActivity gets onNewIntent
SettingLandingFragment gets onViewCreate, onStart and OnResume
As GeneralSettingsFragment gets onStart, that fragment appears for a short moment as a flicker, then SettingsLandingFragment is shown. The expectation is to show SettingLandingFragment without any showing previous screen. It is also a requirement to always switch to SettingsLandingFragment when Settings button is clicked.
The following method is called from onNewIntent of activity to handle navigations and the parameter clearBackStack is passed as TRUE. How to avoid the flicker of previous fragment when a different fragment is requested from different activity? Kindly help me to solve this issue.
private void navigateToFragments(int actionNavigate,
boolean clearBackStack,
Bundle bundle) {
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
.findFragmentById(R.id.nav_host_fragment);
if (navHostFragment != null) {
navController = navHostFragment.getNavController();
NavOptions navOptions;
if (clearBackStack) {
navOptions = new NavOptions.Builder()
.setPopUpTo(navController.getGraph().getId(), true).build();
Logger.d(TAG, "Pop and clearing the all back stack");
} else {
navOptions = new NavOptions.Builder()
.setPopUpTo(actionNavigate, true).build();
Logger.d(TAG, "Pop and clearing the all " +
"intervening destinations up to current navigate destination.");
}
Logger.d(TAG, " Navigate to a destination from the current navigation graph");
navController.navigate(actionNavigate, bundle, navOptions);
} else {
Logger.e(TAG, "NavHostFragment is null");
}
}