Fragment onResume() isn't called when using FragmentPagerAdapter

后端 未结 2 2037
悲哀的现实
悲哀的现实 2021-02-10 00:23

I need my fragments to always call a certain function when they are the active fragment, so I put it in onResume(), but it isn\'t being called.

Fragment A



        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 01:12

    Override Fragment.setUserVisibleHint. When setUserVisibleHint is true call same logic you use for onResume.

    You can see when FragmentPagerAdapter calls setUserVisibleHint in instantiateItem and setPrimaryItem. Applicable to android since 4.2.1 and support-v4.

提交回复
热议问题