Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onResume of new Fragment called before onPause in Android Oreo 8.0

I am facing trouble with android Oreo. My MainActivity has 4 fragments, which replace each other whenever the user presses tabs. Now the problem is, I am saving a value in a singleton instance in onPause. Whenever the user presses the next tab, onResume of that fragment is called before onPause, so I am not able to retrieve the value from the singleton correctly.

like image 961
user3792429 Avatar asked Mar 06 '23 15:03

user3792429


1 Answers

Please use setReorderingAllowed as false to get the normal fragment lifecycle.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
fragmentTransaction.setReorderingAllowed(false);
} 

https://developer.android.com/reference/android/app/FragmentTransaction.html#setReorderingAllowed(boolean)

like image 176
Sathish Kumar Avatar answered Mar 10 '23 12:03

Sathish Kumar