Android fragment OnCreateView twice called

I am using a FragmentPagerAdapter with fragments. My problem is that when I call setCurrentItem, the OnCreateView method of the loadable fragment is called twice. However, it is important to note that the fragment is not recreated, it simply resumes. I desperately want to find a solution that calls OnCreateView only once.

I examined the following questions and a few more, but none of them contains answers for my case:

Android oncreateview called twice

OnCreateView is called several times / Working with ActionBar and fragments

The onCreateView and onActivityCreated snippet is called twice

Most of the questions I found are not related to FragmentViewPagers, which makes them mostly useless.

I would really appreciate any help!

+6
source share
1 answer

I am using a FragmentPagerAdapter with fragments. My problem is that when I call setCurrentItem, the OnCreateView method of the fragment that loads is called twice. It is important to note, however, that the fragment is not recreated, it simply resumes. I am desperately looking for a solution that calls OnCreateView only once.

It is not called twice. What you are experiencing is the default ViewPager , which always caches at least one of its pages ( Fragment ), depending on the value of setOffscreenPageLimit(int limit) . Therefore, onCreateView is called once for each instance returned by getItem

+4
source

All Articles