OnStart () and onStartCommand () still called in 2.0 and above

According to this blog post and the documentation onStartCommand() if you have a Service that you must implement onStart () and onStartCommand (), and in version 2.0 and above only onStartCommand () will be called. It seems that this is not so, and in my service, BOTH is called. This was a problem, as he tried to do this work twice, so I had to add check on onStart () to do nothing if the OS version was <2.0. This seems like a hack and a mistake. Is anyone else experiencing this or maybe something is wrong with me? I cut and pasted the code directly from the sample.

 @Override public int onStartCommand(Intent intent, int flags, int startId) { Util.log(mCtx, "AlerterService", "onStartCommand() called"); handleStart(intent); return super.onStartCommand(intent, flags, startId); } public void onStart(Intent intent, int startId) { Util.log(mCtx, "AlerterService", "onStart() called"); handleStart(intent); super.onStart(intent, startId); } 
+6
source share
2 answers

In this blog post, the base implementations of onStart and onStartCommand not called. Perhaps one of them causes the other.

+3
source

onStartCommand() Source onStartCommand() :

  public int onStartCommand(Intent intent, int flags, int startId) { onStart(intent, startId); return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY; } 

Thus, it still calls onStart();

+11
source

Source: https://habr.com/ru/post/897723/


All Articles