I have following piece of code in onCreate() of a AIDL service
@Override
public void onCreate() {
log("onCreate()");
if (SystemProperties.getInt(DONT_START,0)==1) {
// Do not start the service if some system property is set
log("not starting service");
this.stopSelf();
}
}
This service is "binded to" or started from multiple places. I have logs in all the lifecycle methods. Sometimes I see that when service is started after this.stopSelf() - I see onStartCommand() getting called - but no onCreate() - which indicates that this onStartCommand() has been called on the already stopped service
The logs during the issue - 1% times when it fails looks like :
onCreate()
not starting service"
onBind() return null since service not started
onStartCommand()
The logs in normal flow in same scenario when issue is not seen - 99% times looks like :
onCreate()
not starting service"
onBind() return null since service not started
onCreate()
onStartCommand()
Other similar issues I looked at :
I see in similar thread StopSelf does not stop my service that it was recommended to use :
android.os.Process.killProcess(android.os.Process.myPid());
Should I be using this too instead of
this.stopSelf()