ProgressDialog 的问题
我不明白以下错误:
Activity [myActivity] has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@4050c3f8 that was
originally added here
这是我的代码:
private ProgressDialog progression;
private Handler handler;
private Thread thread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Conteneur général
ui = new RelativeLayout(this);
progression = ProgressDialog.show(this, "SwissParl", "Init", true);
handler = new Handler() {
public void handleMessage(Message msg) {
progression.dismiss();
}
};
thread = new Thread() {
public void run() {
firstMethod();
SecondOne();
andTheLast();
handler.sendEmptyMessage(0);
}
};
thread.start();
setContentView(ui);
}
显然,问题出在我实例化 ProgressDialog 的行上...
知道吗?
I don't understand the following error:
Activity [myActivity] has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@4050c3f8 that was
originally added here
Here is my code:
private ProgressDialog progression;
private Handler handler;
private Thread thread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Conteneur général
ui = new RelativeLayout(this);
progression = ProgressDialog.show(this, "SwissParl", "Init", true);
handler = new Handler() {
public void handleMessage(Message msg) {
progression.dismiss();
}
};
thread = new Thread() {
public void run() {
firstMethod();
SecondOne();
andTheLast();
handler.sendEmptyMessage(0);
}
};
thread.start();
setContentView(ui);
}
Apparently, the problem is on the line where I instanciate my ProgressDialog...
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当显示对话框时活动被破坏时,通常会发生这种情况,例如在显示对话框时旋转或完成活动。
尝试在活动暂停时添加关闭对话框。
That happens normally when the activity is destroyed when showing a dialog, for example rotation or finishing activities while showing dialogs.
Try adding a dismiss dialog onPause of activity.
我不确定问题是什么,但我建议您使用 AsyncTask
像这样的东西
要执行它,请在
onCreate()
内调用new MyBackgroundTask().execute()
它比使用处理程序、线程组合要干净得多......
I'm not sure what the problem is, but i suggest you use an AsyncTask
Something like this
To execute it, call
new MyBackgroundTask().execute()
insideonCreate()
It's far cleaner than using a handler,thread combination...
您尝试在将主视图添加到活动之前显示
ProgressDialog
。在启动ProgressDialog
之前使用setContentView
You are trying to show a
ProgressDialog
before adding the main view to the activity.Use thesetContentView
before you start theProgressDialog