I have a ViewPager with 3 tabs, in each of these tab I can have 2-3 or 4 sub tabs.
When opening the activity, all the tabs (all the fragments) are loaded. Some of the fragments are asking some permissions (can be same permission for different fragment).
My main problem is all the request permission pop up will be displayed when opening this activity. Event if the first fragment visible doesn't need any permission. Is there is a way to ask permission only when the fragment is visible? Or the only solution is to track the click on Tab and the ViewPager OnPageChangeListener?
ViewPager
works. It will instantiate the first visible fragment, and a few on both sides - so if you have 3 fragments, all three will be instantiated,and they will all request their permissions if you're doing it inonCreateView()
If you manage to change it'sDEFAULT_OFFSCREEN_PAGES
member from 1 to 0, you should get your desired effect I guess. – Shark