Question: I want to monitor internet in every page in my project through service. I don't have any code regarding this. I have method how to check internet connection, but I want to implement it through service.

1. Is it possible ? if yes please provide me some methods or logic.

Thanks in advance

Answer: 
From the [source](http://www.juliencavandoli.com/how-to-disable-recent-apps-dialog-on-long-press-home-button/)

```
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

        Log.d("Focus debug", "Focus changed !");

    if(!hasFocus) {
        Log.d("Focus debug", "Lost focus !");

        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);
    }
}

```
```
  @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    Log.d("Focus debug", "Focus changed !");

    if(!hasFocus) {
        Log.d("Focus debug", "Lost focus !");

        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);
    }
}

```