API.AI: How to stop AsyncTask on click of the AIButton?

前端 未结 4 2034
借酒劲吻你
借酒劲吻你 2021-01-18 10:37

I’m using AIButton in my app and I have a AsyncTask which gets executed after AIButton is clicked and receives some command and AsyncTask sometimes

4条回答
  •  鱼传尺愫
    2021-01-18 10:56

    Try to set resultListener for your AIButton and implement onCancelled() method canceling your AsyncTasks from there.

    To mark an AsyncTask as required to stop you should call

    asyncTask.cancel(false);
    

    And in your AsyncTask you have to check periodically whether it was cancelled or not by calling isCancelled(). If this method returns true you should stop execution.

提交回复
热议问题