AsyncTask和Activity的生命周期方法
2012-07-13 17:10
197 查看
Life Cycle Methods and AsyncTask
What will happen if a user clicks the Back button when a progress dialog initiated by an
async task is visible? This will cancel the dialog as per UI guidelines. However, if you
don’t take the precaution of al so cancelling the async task, it will continue to run. So a
good practice is to capture the oncancel of the dialog and exp licitly cancel the async
task.
What happens if you are not using a progress dialog but are the progress through some
other means on the activity? What happens if a user navigates away from the activity
either through a Back button or a press on the Home key? In both these cases, there is
no expectation that the user will come back any time soon. Many times, the right thing
to do is recognize this life cycle state of the activity and then accordingly cancel the
async task.
In short, an async task needs to be fully aware of the life cycle states of the activity. This
may behoove you to actually implement life cycle methods on your task and have the
activity call these life cycle methods so that an async task behaves as if it is a part and
parcel of the activity.
What will happen if a user clicks the Back button when a progress dialog initiated by an
async task is visible? This will cancel the dialog as per UI guidelines. However, if you
don’t take the precaution of al so cancelling the async task, it will continue to run. So a
good practice is to capture the oncancel of the dialog and exp licitly cancel the async
task.
What happens if you are not using a progress dialog but are the progress through some
other means on the activity? What happens if a user navigates away from the activity
either through a Back button or a press on the Home key? In both these cases, there is
no expectation that the user will come back any time soon. Many times, the right thing
to do is recognize this life cycle state of the activity and then accordingly cancel the
async task.
In short, an async task needs to be fully aware of the life cycle states of the activity. This
may behoove you to actually implement life cycle methods on your task and have the
activity call these life cycle methods so that an async task behaves as if it is a part and
parcel of the activity.
相关文章推荐
- Activity的生命周期方法
- 在Activity的生命周期中,会被系统回调的方法
- android学习:android Activity生命周期的七个方法测试
- 亲测Activity生命周期及2个Activity 之间切换触发的的方法时间点
- Activity生命周期方法含义总结
- android学习1#--activity生命周期和onCreat方法
- 在Activity的生命周期中,会被系统回调的方法
- Activity生命周期学习笔记,和横竖切屏时候activity销毁时候保存数据和调用的方法
- Activity生命周期的设计模式:模板方法
- Activity/ViewGroup/View生命周期方法
- Android多个Activity切换时其生命周期中的方法执行顺序
- android-activity生命周期方法
- 第四节--Activity生命周期里的方法介绍
- 第五节--Activity生命周期里的方法之以对话框形式显示Activity界面
- Activity在横竖屏切换、按BACK、按HOME键时执行的生命周期方法总结
- Activity的生命周期及方法
- View的生命周期方法和Activity生命周期方法关系
- Activity的生命周期方法
- android 没有main函数,怎么找到程序执行入口呢?以及activity主要生命周期的方法说明
- Activity的生命周期方法详解和构造图