質問

From my understanding of application lifecycle (including services) it should go onCreate > onStart > onResume.

Based on this understanding, if you shut down the cycle with a this.stopSelf() in the onCreate it should never fire the onStart.

    @Override
public void onCreate()
{
    super.onCreate();
    Log.i(TAG, "Service starting");
    this.stopSelf();
}
@Override
public void onStart(Intent intent, int startId) 
{
    super.onStart(intent, startId);
    Log.i(TAG, "onStart Service");
}

I would expect that the onStart log would not fire. However, LogCat clearly shows that the onStart still runs in spite of the service being terminated in the onCreate.

Is this to be expected? Why is this?

役に立ちましたか?

解決

It is part of the Service lifecycle, as it needs to deliver the intent that started/created the service. I wouldn't recommend using onStart() though, that method is deprecated and replaced by onStartCommand().

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top