Something affect Android UnboundService lifecycle
Bài đăng này đã không được cập nhật trong 7 năm
Context.startService(…)
onCreate();
onStartCommand(…);
onStartCommand()
will be fired each time when we call startService()but
onCreate()` 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
All rights reserved