The onResume fragment is not called

I have 4 (say 1,2,3 and 4) fragments. And at the same time, any of them will be visible to the User. In the second fragment I want to do something when the user comes to it. Now that the user has moved to the third fragment and clicked the "Back" button, I want to run some code. My onResume problem onResume not caused when the user clicks the back button and goes to the second fragment.

+8
android android-fragments android-fragmentactivity onresume
source share
2 answers

I recently ran into the same problem, I know that it's too late, but just in case someone is looking for her, here is my answer:

Thanks @fasteque for narrowing my search.

The onResume() or onPause() fragments will be called only when the onResume() or onPause() actions are onResume() . They are closely related to activities.

But if you still want to listen to changes in your activity, for example, which fragment is on top and trigger events accordingly, you can take a look at the FragmentManager.OnBackStackChangedListener

Hope this helps :)

+4
source share

I had the same problem. If you want to switch from the third fragment to the second fragment (using the "Back" button or in another way), you can call the second fragment in onPause of the third fragment.

 @Override public void onPause() { super.onPause(); Fragment2 fragment2= (Fragment2) getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment2); if (fragment2!= null) { //you can call any function from fragment2 fragment2.SomeFunctions(); } } 
+1
source share

All Articles