【发布时间】:2010-09-22 19:57:25
【问题描述】:
我的应用经常抛出如下异常:
E/WindowManager(6282): android.view.WindowLeaked: 活动 com.myActivity 已泄露窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@4479b710 那 最初是在这里添加的
当主 Activity 启动和启动任务时,应用会显示一个进度对话框。任务完成后,它将关闭进度对话框。
我的代码如下所示。有人可以帮我吗?
public class MyActivity extends Activity {
private static int ID_DIALOG_PROGRESS = 2001;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
showDialog(ID_DIALOG_PROGRESS);
new MyTask().execute(null, null, null);
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == ID_DIALOG_PROGRESS) {
ProgressDialog loadingDialog = new ProgressDialog(this);
loadingDialog.setTitle("");
loadingDialog.setMessage("");
loadingDialog.setIndeterminate(true);
loadingDialog.setCancelable(false);
return loadingDialog;
}
return super.onCreateDialog(id);
}
private class MyTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
/* Do something expensive here...*/
/* Start other activity*/
Intent intent = new Intent(MyActivity.this, OtherActivity.class);
startActivityForResult(intent, 1000);
}
return null;
}
protected void onPostExecute(Void arg0) {
dismissDialog(ID_DIALOG_PROGRESS);
}
}
}
大多数时候,异常是从 showDialog() 调用中引发的。另一次,dismissDialog() 调用引发了异常。
提前谢谢你!
【问题讨论】:
标签: android