Android:dialog和AsyncTask-为什么我会得到一个IllegalArgumentException?
我有一个这样的活动:Android:dialog和AsyncTask-为什么我会得到一个IllegalArgumentException?,android,android-asynctask,Android,Android Asynctask,我有一个这样的活动: public class StudentActivity extends Activity { static final int DIALOG_PROGRESS = 0; public void btnSyncStudentsClick(View view) { syncStudents(); } @Override protected Dialog onCreateDialog(int id) { Dialog d = null; switch
public class StudentActivity extends Activity {
static final int DIALOG_PROGRESS = 0;
public void btnSyncStudentsClick(View view) {
syncStudents();
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch (id) {
case DIALOG_PROGRESS:
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage(getText(R.string.txt_refreshing_students));
d = dialog;
break;
return d;
}
private class RefreshStudentTask extends
AsyncTask<Void, Integer, AccountRefreshResult> {
@Override
protected void onPreExecute() {
showDialog(DIALOG_PROGRESS);
}
@Override
protected AccountRefreshResult doInBackground(Void... params) {
//some network requests
}
@Override
protected void onPostExecute(AccountRefreshResult result) {
dismissDialog(DIALOG_PROGRESS); //this throws an exception
//some other stuff
}
}
}
我无法在我这方面复制此问题,因此调试非常困难
编辑:
活动应仅在纵向模式下运行:
android:screenOrientation="portrait"
您的对话已被取消。这是一种中等常见的比赛条件。只要捕获异常并继续,无论哪种方式,结果都是一样的-对话框消失了。您可能可以通过执行启动对话框的任何操作,然后更改方向来复制此操作,因为活动将在没有对话框的情况下重新创建。这是处理对话框的诸多烦恼之一,因此,谷歌建议您改用它,因为它可以为您管理许多这样的边缘案例。您的对话框是否显示。。?它说它没有显示..在我的设备上它正在显示。我不知道这个有问题的设备怎么样。我只有堆栈跟踪,但只有一个dismissDialog()调用,它应该始终在showDialog()之后运行。如何取消?方向更改(或其他配置更改)会导致活动重新启动,这是一种方式(异步任务不会自动取消,因此它会结束,但会有一个死对话框的句柄)。但是不管怎样,这是一个可以忽略的安全选项-你想让对话框消失,它就消失了。那么活动应该只在纵向模式下运行(参见我编辑的帖子)
ProgressDialog
是否可以取消?当它启动时按下后退按钮会发生什么?是的,它是可以取消的,但按下“后退”不会复制错误
android:screenOrientation="portrait"