I have written a simple code to check the use of service .
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("msg","Service Started");
if(intent == null)
Log.w("msg","Service Intent NULL");
g = (GlobalVar) getApplicationContext();
try {
Thread thread = new Thread(new Job());
thread.start();
} catch (Exception ex) {
Log.e("msg", ex.getMessage());
}
return START_STICKY;
}
There are two buttons in my activity. One button starts the service using startService(Intent intent) method and other one stops it using stopService(Intent intent) method. 1. I pressed the startButton and the msg Service Started is printed in Logcat. Intent will not be null this time. 2. Now , I go to Emulator's Settings>Applications>Running Services and locate my service and stop it. The msg Service Stopped is printed in the Logcat which I have written in the onDestroy() method of the service.
Here is the part which I don't understand.
The Android System restarts the service itself after some seconds and this time the msg Service Started is not printed. The documentation states that intent will be null. BUT the msg Service Intent NULL is also not printed.
How do I know that android system restarts the service?
I have printed some messages in the Thread that my service starts . Those msgs start printing automatically in the logcat after few seconds of stopping the service from the emulator settings.
Any ideas why those LogCat messages are NOT being printed ?