Newer
Older
CosmosClient / app / src / main / java / com / example / cosmosclient / services / CosomosBackgroundService.java
package com.example.cosmosclient.services;

import android.app.IntentService;
import android.content.Intent;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;


public class CosomosBackgroundService extends IntentService implements LocationListener {

    public CosomosBackgroundService() {
        super("CosomosBackgroundService");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("debug", "onCreate");
    }

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

        Log.d("debug", "onStartCommand");

//        Thread thread = new Thread() {
//            public void run() {
//                int count = 10;
//
//                try {
//                    for(int i=0 ; i< count ; i++) {
//                        Thread.sleep(1000);
//
//                        Log.d("debug", "sleep: " + String.valueOf(i));
//                    }
//
//                } catch (InterruptedException e) {
//                    Thread.currentThread().interrupt();
//                }
//            }
//        };
//        thread.start();


        return super.onStartCommand(intent,flags,startId);
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        Log.d("debug", "onHandleIntent");
        int count = 10;

        try {
            for(int i=0 ; i< count ; i++) {
                Thread.sleep(1000);

                Log.d("debug", "sleep: " + String.valueOf(i));
            }

        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

    }

    @Override
    public void onDestroy() {
        Log.d("debug", "onDestroy");

        super.onDestroy();
    }

    @Override
    public void onLocationChanged(Location location) {

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onProviderDisabled(String provider) {

    }
}