21

I am using the new android Navigation Framework in one of my Applications. The purpose of Application is to behave as a launcher.

Sometimes when I try to change the fragment (navigate using the navcontroller) it doesn't change the fragment instead it logs

Ignoring navigate() call: FragmentManager has already saved its state

i know this question been asked before here Ignoring navigate() call: FragmentManager has already saved its state but it doesn't have a Solution.

I am navigating using the following code:

Navigation.findNavController(view).navigate(R.id.action_next, bundle)

Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
Faizan Ahmed
  • 251
  • 1
  • 7

1 Answers1

0

I had the same problem, in my case I was trying to use navigate() inside the Mopub ad callback onInterstitialDismissed, and was getting this info.

My solution for this case to use LiveData like this:

 private var dismissState = MutableLiveData<Int>(0)
 mMobupInterStitialAd?.interstitialAdListener = object : MoPubInterstitial.InterstitialAdListener {
 override fun onInterstitialDismissed() {

 dismissState.value=1
 }
 }
override fun onViewCreated() {
 dismissState.observe(viewLifecycleOwner) {
 if(it == 1) {
 findNavController.navigate(R.id.fragmentAtoFragmentB)
 }
 }
}

This is how I solved the problem.