In my Service, I have return START_STICKY
to make my Service
restart again after I kill app.
I have test and it work in device Samsung
, Sony
, LG
but in Xiaomi
it not work (service not start again)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
How can I handle this case. Any help or suggestion would be great appreciated?
From the Android docs
/**
* Constant to return from {@link #onStartCommand}: if this service's
* process is killed while it is started (after returning from
* {@link #onStartCommand}), then leave it in the started state but
* don't retain this delivered intent. Later the system will try to
* re-create the service. Because it is in the started state, it will
* guarantee to call {@link #onStartCommand} after creating the new
* service instance; if there are not any pending start commands to be
* delivered to the service, it will be called with a null intent
* object, so you must take care to check for this.
*
* <p>This mode makes sense for things that will be explicitly started
* and stopped to run for arbitrary periods of time, such as a service
* performing background music playback.
*/
public static final int START_STICKY = 1;
Some devices like Xiaomi and Vivo have an extra permission called "auto start" which allows your app service to be restarted automatically after being killed. You can find it in additional permissions in Xiaomi I guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With