Reputation: 1877
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}
This exception is thrown after Toast.show() and right after that,start a new activity (the main one) instead of finish() the current.
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.
}
}
};
When passing to the new activity it 'forgets' that the dialog was introduced in previous activity. What should I do?
BTW its not always throws ,only from time to time. Thanx!!!
EDIT : Some more code (of the dialog thread)
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;
}
}
I guess dismissDialog(typeBar); is the wrong method to stop this thread. I don't know where I should put state=ProgressThread.DONE in the code
EDIT2:
I've added the code that declares the dialog and parts of onCreate of the Activity:
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;
}
Upvotes: 0
Views: 947
Reputation: 1877
this is how i've solved this issue:
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){
progThread.setState(ProgressThread.DONE);
// dismissDialog(typeBar); // PROBLEMATIC
mail_sent_popup.show(); // mail sent popup
startActivity(new Intent(cntx,MainScreenActivity.class));
// start the main instead of finishing this one.
}
}
};
Just commented the manual dismissDialog and let the thread die with progThread.setState(ProgressThread.DONE); hope this helps somebody.
Upvotes: 0
Reputation: 95626
Generally, a Dialog is owned by a single Activity. You can't show a dialog in ActivityA and then dismiss it in ActivityB.
Upvotes: 1