E/AndroidRuntime(16172): FATAL EXCEPTION: main
E/AndroidRuntime(16172): java.lang.IllegalArgumentException: no dialog with id 2 was ever shown via Activity#showDialog
E/AndroidRuntime(16172): at android.app.Activity.missingDialog(Activity.java:2600)
E/AndroidRuntime(16172): at android.app.Activity.dismissDialog(Activity.java:2585)
E/AndroidRuntime(16172): at com.proapps.eng.android.client.meeting_screen$1.handleMessage(meeting_screen.java:196)
E/AndroidRuntime(16172): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(16172): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(16172): at android.app.ActivityThread.main(ActivityThread.java:3701)
E/AndroidRuntime(16172): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(16172): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(16172): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/AndroidRuntime(16172): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
E/AndroidRuntime(16172): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 238): Force finishing activity com.proapps.eng.android.client/.MainScreenActivity
W/ActivityManager( 238): Activity pause timeout for HistoryRecord{2b54bd38 com.proapps.eng.android.client/.MainScreenActivity}
在 Toast.show() 之后抛出此异常,然后立即开始一个新活动(主要活动)而不是当前的 finish()。
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
// Get the current value of the variable total from the message data
// and update the progress bar.
int total = msg.getData().getInt("total");
progDialog.setProgress(total);
if (total <= 0){
dismissDialog(typeBar);
progThread.setState(ProgressThread.DONE);
mail_sent_popup.show(); // mail sent popup
startActivity(new Intent(cntx,MainScreenActivity.class));
// start the main instead of finishing this one.
}
}
};
当传递给新活动时,它“忘记”对话框是在以前的活动中引入的。我应该怎么办?
顺便说一句,它并不总是抛出,只是不时抛出。谢谢!!!
编辑:更多代码(对话线程)
private class ProgressThread extends Thread {
// Class constants defining state of the thread
final static int DONE = 0;
final static int RUNNING = 1;
Handler mHandler;
int mState;
int total;
EditText name_text = (EditText)findViewById(R.id.editText1);
EditText phone_text = (EditText)findViewById(R.id.editText2);
EditText free_text = (EditText)findViewById(R.id.editText3);
// Constructor with an argument that specifies Handler on main thread
// to which messages will be sent by this thread.
ProgressThread(Handler h) {
mHandler = h;
}
// Override the run() method that will be invoked automatically when
// the Thread starts. Do the work required to update the progress bar on this
// thread but send a message to the Handler on the main UI thread to actually
// change the visual representation of the progress. In this example we count
// the index total down to zero, so the horizontal progress bar will start full and
// count down.
@Override
public void run() {
mState = RUNNING;
total = maxBarValue;
while (mState == RUNNING) {
// LONG JOB HERE
}
Message msg = mHandler.obtainMessage();
Bundle b = new Bundle();
b.putInt("total", 0);
msg.setData(b);
mHandler.sendMessage(msg);
}
}
// Set current state of thread (use state=ProgressThread.DONE to stop thread)
public void setState(int state) {
mState = state;
}
}
我猜dismissDialog(typeBar); 是停止此线程的错误方法。我不知道我应该把 state=ProgressThread.DONE 放在代码中的哪个位置
编辑2:
我添加了声明对话框和部分活动 onCreate 的代码:
public void onCreate(Bundle savedInstanceState) {
...
...
showDialog(2);
...
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,mDay);
case TIME_DIALOG_ID:
return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute,false);
case 2:
progDialog = new ProgressDialog(this);
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDialog.setMessage("Sending...");
progThread = new ProgressThread(handler);
progThread.start();
return progDialog;
}
return null;
}