AsynchTask 将 onPostExecute() 方法绑定(bind)到 UI 线程。假设我们通过按后退按钮关闭 Activity ,而 AsynchTask doInBackground() 方法仍在进行中。
- 我想知道考虑到 Activity 不再显示在屏幕上,onPostExecute 是否会执行?
- 如果答案是肯定的,是否会导致异常? (因为访问不再显示在屏幕上的 UI 对象)。
最佳答案
1-I want to know will onPostExecute executes by considering that activity is not displaying on screen anymore?
是的!
2-In case answer is yest, will it cause exceptions or not? (because of accessing UI objects which are not longer displayed on screen).
是的!它可能会导致异常,因为您在 AsyncTask 中使用的 Activity 实例和 View 不再存在
此链接将为您提供更多帮助:AsyncTask won't stop even when the activity has destroyed
关于android:Activity完成后Asynchtask的onPostExecute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18942078/