Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not navigate while app is in background

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
like image 421
Илья Останин Avatar asked Nov 15 '19 07:11

Илья Останин


People also ask

What is restrict background activity?

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.

What happens when app goes to background?

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.

What happens when apps run in the background on Android?

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.

Why are there restrictions on the background of an app?

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".

How to fix Windows 10 cannot run apps in 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.

What happens when an app attempts to start a new activity?

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.


1 Answers

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.

like image 192
Guillaume Imbert Avatar answered Oct 12 '22 06:10

Guillaume Imbert