Reputation: 97
I have been using the following... https://bitbucket.org/owentech/testswipeab/src/eb30782019b2/src/com/owentech/testswipeab/
as an example for implementing an android app with swipe-able tabs and fragments (replacing the dummy fragments w/ my own) This works well for me except for one issue. As you swipe between tabs, the fragment's onresume method is not getting called. In fact, the onresume methods are only getting called when the app first starts. I would like the appropriate onresume method to get called for each time the tab is switched to that fragment.
Any suggestions on how to modify this sample code to achieve this would be appreciated.
Upvotes: 2
Views: 1286
Reputation: 2591
Fragment lifecycle is almost identical to common Activity lifecycle - an instance is being created once but can be deactivated or reactivated multiple times. So if you have code that needs to be executed each time the same fragment instance is reactivated or deactivated, then move that code into onResume or onPause respectively.
onCreateView is called in between the calls onCreate and onActivityCreated - hence only once per fragment lifecycle.
See the documentation link http://developer.android.com/reference/android/app/Fragment.html
Upvotes: 3