12/08/2018, 16:24

Something affect Android UnboundService lifecycle

Context.startService(…) onCreate(); onStartCommand(…); onStartCommand() will be fired each time when we call startService()butonCreate()` only call once time Context.stopService(…) onDestroy(); stopSelf() onDestroy(); Go to background START_STICKY nothing ...

Context.startService(…)

onCreate();
onStartCommand(…);

onStartCommand() will be fired each time when we call startService()butonCreate()` only call once time

Context.stopService(…)

onDestroy();

stopSelf()

onDestroy();

Go to background

START_STICKY

nothing fired

START_NOT_STICKY

onDestroy();

Kill app from Recent app

START_STICKY Normally

onTaskRemove();
onCreate();
onStartCommand(…);

However, for some device, like Xiaomi, Huwaei there is no method fired. The reason is in this device when we Kill app from Recent it also Force Stop app START_NOT_STICKY

nothing fired (service already destroyed when go to background)

Stop in Setting->…->Running Service ->ExampleService

onDestroy();

Force Stop in Setting->Apps->ExampleApp

nothing fired
0