Question: I'm using viewPager to create a layout with tabs and in each tab I use a Fragment. One of them is to get all de user contacts and put it on a ListView. But I want to call de AssyncTask only if the Fragment is displayed on screen.

is there a method to do it?
TY

Answer: 
you can use 

```
@Override
public void setUserVisibleHint(boolean isVisibleToUser)
{
    super.setUserVisibleHint(isVisibleToUser);
    if(isVisibleToUser)
    {
       //things to do when fragment is visible
    }
}

```

Even it is called before onCreateView.
You can check to see if it's visible with `.isVisible()` something like this 

```
MyFragmentClass fragment = (MyFragmentClass) getSupportFragmentManager().findFragmentByTag("fragmentTAG");

if (fragment != null && fragment.isVisible()) {
     // call AsyncTask
}

```