Android中AsyncTask与进度对话框的高级应用
1. 非UI片段作为中介
在Android开发中,我们可以使用非UI片段作为活动与 AsyncTask 之间的中介。通过设置片段为保留状态,它可以在配置更改时存活下来。以下是相关代码示例:
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();
}
}
这个非UI片段的主要作用如下:
超级会员免费看
订阅专栏 解锁全文
31

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



