I use Navigation Component to navigate between fragments.
Init navigation in main activity:
val navHostFragment = NavHostFragment.create(R.navigation.nav_graph)
supportFragmentManager
.beginTransaction()
.replace(R.id.container, navHostFragment)
.commit()
Navigation to another fragment in splash fragment:
findNavController().navigate(SplashFragmentDirections.actionSplashFragmentToHomeActivity())
In splash i do auth, it takes some time, after auth i navigate to home fragment. If i minimize app (press home button) in splash fragment then navigate() doesn't work and when i open app again it remains in splash fragment
In console:
NavController: Ignoring popBackStack to destination my.app/homeFragment as it was not found on the current back stack
FragmentNavigator: Ignoring navigate() call: FragmentManager has already saved its state
So when you restrict the background data, the apps will no longer consume the internet in the background, i.e. while you are not using it. It will use the internet only when you open an app. This even means you won't get real-time updates and notifications when the app is closed.
An app is running in the background when both the following conditions are satisfied: None of the app's activities are currently visible to the user. The app isn't running any foreground services that started while an activity from the app was visible to the user.
Apps that can run in the background can send and receive notifications, sync information, and stay up to date. If you find that an app is using a lot of battery when running in the background, you can change the setting for apps that allow it.
These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen. Note: For the purposes of starting activities, an app running a foreground service is still considered to be "in the background".
If it isn’t there, right-click inside the right panel and select New>SWORD (32-bit) Value. Name it Migrated, and set its value to 4. Customize the Let apps run in the background setting however you like i.e., disable it completely or disable it for select apps. Next, restart your system and this time, the settings should persist after the reboot.
Note: When such an app attempts to start a new activity, the system places that activity on top of the app's existing task but doesn't navigate away from the currently-visible task. When the user later returns to the app's task, the system starts the new activity instead of the activity that had previously been on top of the app's task.
When you get your auth callback, test if your app is in foreground and if so, navigate. Do nothing if your app is in background.
In the onResume method of the splashscreen, test if your user is authenticated. If so, skip your splashscreen.
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