sanjay_ sanjay_ - 11 months ago 35
Android Question

How to perform certain task inside a fragment only when a TabLayout is active?

I'm working on an android app which involves token change on every data request to the server. So, each time, i'll need to send a new token to the server otherwise the user must re-login.

I'm having trouble with tab layout, where the request are simultaneous. Is there any way of sending request to the server only when a tab is active?

PS. I tried using handler which send the request after 2 seconds but it's not effective.


You can override this fragment method:

public class Your class extends Fragment {

    public void setMenuVisibility(final boolean visible) {

        if (visible)
            //launch task