ViewPager typically used to move an effective horizontal element into an item navigation. Typical use cases:
- Scrolling related items (such as email messages, images, album songs, etc.).
- Scrolling between tabs
- Scrolling back and forth while working with the wizard.
For more information, you can read the Android Swipe Views Sample Design section.
As for the life cycle, it basically uses the same life cycle as any other fragment. The only difference is that life cycle methods can be called a bit later or earlier than you expect, due to fragment caching, ViewPager implements.
I am not sure exactly when I should initialize / free a member of the child class.
You should mainly rely on two methods: onStart() and onStop() . In onStart() you create class members and initialize whatever you want. In the onStop() method, you must uninitialize everything and remove all the listeners that you set to onStart() .
The setUserVisibleHint() method is used regardless of onStart() or onStop() . You better not try to initialize or destroy anything there. You should not consider this a life cycle method because it is not. This is just to give you a hint that your fragment is visible to the user. Here you can start or stop the animation, or request data updates or perform similar tasks. This is the only goal of this method.
The required suggestion from you guys would be preferable to use PageViwer in this case, or I have to go with the traditional flow of activity for each of the components.
If your activity corresponds to one of the points in question, I suggest you use ViewPager . Otherwise, you may consider other options.
Update: Most likely, you will not often override the onCreate() and onDestroy() fragment life cycle methods. Instead, you will use the onCreateView() and onDestroyView() methods. There you can implement the so-called static initialization, the initialization of which does not change while the fragment is still alive. This is a layout initialization and similar tasks.
sergej shafarenka Aug 14 '14 at 8:49 2014-08-14 08:49
source share