在我的服务中,我已经返回了
我已经测试过,在三星、索尼和LG设备上可以正常工作,但在小米设备上无法工作(服务未能重新启动)。
我该如何处理这种情况?非常感谢您的帮助和建议。
来自安卓文档。
START_STICKY
,以便在我杀死应用程序后重新启动我的Service
。我已经测试过,在三星、索尼和LG设备上可以正常工作,但在小米设备上无法工作(服务未能重新启动)。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
我该如何处理这种情况?非常感谢您的帮助和建议。
来自安卓文档。
/**
* 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;
ontaskRemoved
也无法被调用,就像我在这里提出的问题一样:http://stackoverflow.com/questions/41629152/service-ontaskremoved-not-call-when-kill-app-in-some-device - Linh小米
厂商特定的问题。 - Onik