androidfragmentandroid-8.0-oreofragment-lifecycle

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.


Solution

  • There is some problem with Fragment in oreo version.I created a separate app to check what lifecycle functions are called when we replace one fragment with other..Here is the log:

    MainActivity onCreate ->
    FragmentA oncreate ->
    FragmentA oncreateView ->
    MainActivity onStart ->
    FragmentA onStart ->
    MainActivity onResume ->
    FragmentA onResume ->
    Button Pressed;that replace fragment A with Fragment B
    FragmentB onCreate ->
    FragmentB onCreateView ->
    FragmentB onStart ->
    FragmentB onResume ->
    FragmentA onPause ->
    FragmentA onStop ->
    FragmentA onDestroy ->
    

    I was importing import android.app.Fragment.It worked when I replaced it with android.support.v4.app.Fragment .