Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我们可以创建一个像STICKY一样的IntentService吗?_Android_Intentservice_Android Intentservice - Fatal编程技术网

Android 我们可以创建一个像STICKY一样的IntentService吗?

Android 我们可以创建一个像STICKY一样的IntentService吗?,android,intentservice,android-intentservice,Android,Intentservice,Android Intentservice,该文档称intentservice隐式调用stopself。所以我想知道intentservice是否可以变得粘乎乎的 感谢sticky就像一个属性(它不是属性),您可以将它提供给一个服务,在系统因内存不足而关闭它之后,它会被激活,当系统有足够的内存时,它会重新启动服务,并在onstart命令上返回START\u sticky,否则将保持关闭状态。在IntentServices中,您不能返回START\u STICKY(至少我还没有找到方法),但您可以做的是: @Override pub

该文档称intentservice隐式调用stopself。所以我想知道intentservice是否可以变得粘乎乎的

感谢

sticky就像一个属性(它不是属性),您可以将它提供给一个服务,在系统因内存不足而关闭它之后,它会被激活,当系统有足够的内存时,它会重新启动服务,并在onstart命令上返回START\u sticky,否则将保持关闭状态。在IntentServices中,您不能返回START\u STICKY(至少我还没有找到方法),但您可以做的是:

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        return START_REDELIVER_INTENT;
    }

目前我正在我的应用程序中使用它,它运行良好

是的,它可能会有粘性,但服务仍会调用stopSelf(),这会像停止自己然后一直重新启动一样吗?不,如果你调用stopSelf,它会停止,直到你再次启动服务,它不必调用stopSelf(),它会自己调用stopSelf(),这就是为什么它是一个intentservice,我的问题是,当它自己调用stopself()时,它会再次重新启动还是保持停止状态?不会,如果stopself被调用,直到您再次启动服务为止