Android AsyncTasks How to Check If activity is still running

前端 未结 8 1468
时光说笑
时光说笑 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:17

    As this part of one training on Android Developers suggests, keep a WeakReference on the UI element that needs to be updated after task is done and check if the reference is null before using it. This helps not only in checking if the UI is still around, but also does not prevent UI elements from being garbage collected.

提交回复
热议问题