How to force an IntentService to stop immediately with a cancel button from an Activity?

后端 未结 9 887
梦如初夏
梦如初夏 2020-11-30 00:10

I have an IntentService that is started from an Activity and I would like to be able to stop the service immediately from the activity with a \"cancel\" button in the activi

9条回答
  •  再見小時候
    2020-11-30 01:08

    @Override
    protected void onHandleIntent(Intent intent) {
        String action = intent.getAction();
        if (action.equals(Action_CANCEL)) {
            stopSelf();
        } else if (action.equals(Action_START)) {
            //handle
        }
    }
    

    Hope it works.

提交回复
热议问题