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);
    }
}

```
For disable the recent apps button while launching other applications then you can create a service. 

public class StatusBarService extends Service {

```
private static final String TAG = StatusBarService.class.getSimpleName();

private volatile boolean isRunning;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();

    isRunning = true;

    // Lock a recentApps button
    RecentAppLockerThread thread = new RecentAppLockerThread();
    new Thread(thread).start();

}

/**
 * Lock a recent apps button
 * 
 * 
 */
private class RecentAppLockerThread implements Runnable {

    @Override
    public void run() {
        while (isRunning) {
            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            sendBroadcast(closeDialog);          
        }
    }

}

@Override
public boolean stopService(Intent name) {
    isRunning = false;
    return super.stopService(name);
}

@Override
public void onDestroy() {
    super.onDestroy();
    isRunning = false;
}

```

}