I have an application running on an embedded system with 4 tabs in a SectionsPagerAdapter and in the Fragment of each tab I have code that updates the display every 0.5 seconds via a timer.
I find that when I create 4 tabs, the first 2 are created and 3 and 4 are only created if I scroll to the right which is expected.
The issue for me is that after the view for each tab is created and the timer is started, the timer fires and the calls to update the views gets processed even if the tab is not visible.
I am trying to find a way to know if the tab is visible or not and if it's hidden, I simply skip the re-drawing of the views. Only when the tab is visible do I do the updates.
I have tried using isShown() and hasWindowFocus() from the the view that getView() returns but they always return true;
I've also tried to use onPause and onResume for each fragment but they only get called when I move to the 2rd tab from it. Eg, on tab1, move to tab2, not called, moved to tab3, onPause() called.
For now I have used onTabSelected() to store the current tab in my singleton class that all the fragments have access to the system data from. When I create the fragment, I pass in the tab position.
BUT , how can I check for this view being visible in a more elegant way?