IntentService will be killed after I stop my application

后端 未结 5 1078
栀梦
栀梦 2021-02-05 11:50

I am referring to android design considerations: AsyncTask vs Service (IntentService?)

According to the discussion, AsyncTask does not suit, because it is ti

5条回答
  •  星月不相逢
    2021-02-05 12:40

    In your IntentService you can override onStartCommand() returning START_REDELIVER_INTENT

    Then if killed, your service will be restarted automatically by the system after some time with the same Intent.

    Be sure to call the super implementation on onStartCommand() like this:

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

提交回复
热议问题