enter "finish" state when not calling finish() causing BadTokenException
I have a very weird behaviour, which I cant find its cause. the last thing I do on onCreate() is to call a certain method. in that method i use
progressDialog = ProgressDialog.show(this, null, "Registering with Moish'd! server", true, false);. on the first run i get BadTokenException: Unable to add window on the progressDialog line. the second run it passes it. I read in forums that if the activity is in the middle of "finish" process than it might cause such an excetion. after a long debugging tests, i tried asking for isFinishing(). something odd accoured - before calling the method, isFinishing() returns false.in the first line of the method I ask again and now isFinishing() returns true. how can it be ?!? in the last line before entering a method its not "finishin开发者_如何转开发g" and in the first line of the method its suddenly "finishing", when NOTHING is happening in between (certainly not calling finish()). anyone ?!?I don't think you can popup a ProgressDialog
in onCreate
as the main window of your Activity
has not yet been drawn. Try moving the ProgressDialog.show()
call to your onResume
method.
UPDATE
Ok, perhaps you can try this then:
private static final int DIALOG_INIT = 0;
...
public void onCreate(Bundle savedInstanceState) {
...
showDialog(DIALOG_INIT);
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch (id) {
case DIALOG_INIT:
dialog = new ProgressDialog(this);
((ProgressDialog) dialog).setMessage("Registering with Moish'd! server");
//other dialog setup
break;
}
return dialog;
}
精彩评论