高级异步任务与进度对话框详解
1. 非 UI 片段的作用
在 Android 开发中,为了更好地处理异步任务和应对配置更改,我们可以使用非 UI 片段作为活动与异步任务之间的中介。以下是相关代码示例:
else {
mlt = new MyLongTask(ctx, ctx, "Task1");
String[] params = this.getArguments()
.getStringArray("params");
mlt.execute(params);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
// When the activity is going away, make sure
// to dismiss the dialog if it's there.
@Override
public void onDetach() {
super.onDetach();
Log.d(tag, "calling for dismissal of the dialog");
if(mlt != null) {
mlt.dismissDialog();
}
}
1.1 配置更改处理
通过将片段设置为保留( setRetainInst
超级会员免费看
订阅专栏 解锁全文
47

被折叠的 条评论
为什么被折叠?



