public class MyService extends Service {

    final String TAG = "MyService";

    Timer t = null;

    public MyService() {

       Log.i("MyService", " ------------------- constructor");

    }

    @Override

    public void onCreate() {

        Log.i("MyService", " ------------------- onCreate");

        t = new Timer();

        usageAccessSettingsPage();

        t.scheduleAtFixedRate(new TimerTask() {

            @Override

            public void run() {

                printForegroundTask();

            }

        }, 0, 1000);

    }

    @Override

    public int onStartCommand(Intent intent, int flags, int startId) {

       Log.i("MyService", " ------------------- onStartCommand");

      return START_STICKY;

    }

    @Override

    public IBinder onBind(Intent intent) {

      // TODO: Return the communication channel to the service.

      throw new UnsupportedOperationException("Not yet implemented");

    }

    @Override

    public void onTaskRemoved(Intent rootIntent) {

       Log.i("MyService", " ------------------- onTaskRemoved");

      super.onTaskRemoved(rootIntent);

    }

    @Override

    public void onDestroy() {

        Log.i("MyService", " ------------------- onDestroy");

        super.onDestroy();

    }
}