Fragment onResume not called

hemu picture hemu · Mar 13, 2013 · Viewed 7k times · Source

I am having 4 (let's say 1,2,3 & 4) fragments. And at a time any one of them will be visible to User. In 2nd fragment I want to do something when user is coming on it. Now when User navigated to 3rd fragment & hits the back button, I want to run a some code. My problem is onResume is not getting called when user hits the back button & come to 2nd fragment.

Answer

Ankit Popli picture Ankit Popli · Feb 20, 2014

I recently bumped into the same problem, I know that its too late, but just in case some one else is looking for this, here's my answer:

Thanks @fasteque for narrowing down my search.

The fragments onResume() or onPause() will be called only when the Activities onResume() or onPause() is called. They are tightly coupled to the Activity.

But if you still want listen to the changes in your activity like which fragment is on top, and trigger events accordingly, you might wanna have a look at FragmentManager.OnBackStackChangedListener

Hope this helps :)