Android AsyncTasks How to Check If activity is still running

前端 未结 8 1639
时光说笑
时光说笑 2021-02-07 04:25

I have used AsyncTasks with my application, in order to lazy download and update the UI.

For now my AsyncTasks updates the UI real simply:

8条回答
  •  半阙折子戏
    2021-02-07 05:14

    I will insist that you that if you Activity is not running why don't you cancel the AsyncTask? That would be a better and feasible solution. If you Application is running say you move from one Activity to another then it won't give error AFAIK.

    But, I would insist to cancel the AsyncTask then you'r Activity is not running, you can check AsyncTask is running or not,

    if(task != null && task.equals(AsyncTask.Status.RUNNING))
    task.cancel(true);
    

提交回复
热议问题