admin 管理员组

文章数量: 1086019


2024年1月4日发(作者:fscanf的正确调用形式)

();new Thread(new Runnable() {public void run() {(10000);/** IllegalArgumentException: View not attached to window manager* If the activity showing the dialog was killed before dismiss() out of rotation or locale changed,* the dialog will gone with activity, but when dismiss() yields "IllegalArgumentException: View not attached to* window manager".* Checking isShowing() won't help.* Checking shing() won't help, either.* Dismiss it in main thread also won't give any help.*/// THIS WON't WORK// if (ing()) {// s();// }// if (!shing()) {// s();// }Message msg = (); = DISMISS_DIALOG; = dialog;ssage(msg);}}).start();}});final Button better = (Button) findViewById();lickListener(new kListener() {public void onClick(View v) {mBetterDialog = new ProgressDialog();le("Better dialogging");sage("This dialogging can be used. The dialog object is a field of its activity, so activity can" +

" control it to make sure dialog only lives within activity lifecircle");eterminate(true);celable(true);// You MUST do the show in main thread ();new Thread(new Runnable() {public void run() {(10000);/** This is much better, mBetterDialog is a field of its activity, so activity can take care of it in order* to make sure dialog only live within activity's life circle, to avoid any unexpected exceptions.*/// THIS really worksif (mBetterDialog != null && ing()) {s();}}}).start();}});final Button optional = (Button) findViewById(al);lickListener(new kListener() {@SuppressWarnings("deprecation")public void onClick(View v) {showDialog(0);new Thread(new Runnable() {public void run() {(10000);/** This way works best for most of time, except if activity died before dismissing, exception must be* thrown: "IllegalArgumentException: View not attached to window manager".* Although activity takes care of its belonging dialog, there is no way to operate it manually any more.* First you do not have reference to dialog object and second, any manual operation only interferences* and breaks state maintained by frameworks.

*/dismissDialog(0);}}).start();}});}@Overrideprotected Dialog onCreateDialog(int id) {ProgressDialog d = new ProgressDialog(this);le("Optional dialogging");sage("This dialogging scheme works best for most times, the dialogs are all taken care of by activitys andframeworks" +". Except for activity being killed during dialog showing");eterminate(true);celable(true);return d;}@Overrideprotected void onDestroy() {roy();// Activity is dying, all its belonging dialogs should be dismissed, of (mBetterDialog != null && ing()) {s();mBetterDialog = null;}// For dialogs showed via showDialog(int), no way to stop it in onDestroy()// dismissDialog(0); // cause "IllegalArgumentException: no dialog with id 0 was ever shown via Activity#showDialog"// This is because Activity has to manage its dialog during onPause() and onResume() to restore// dialogs' state. So if you manually dismiss it in onDestroy(), it will cause JE.// removeDialog(0);// cause "IllegalArgumentException: no dialog with id 0 was ever shown via Activity#showDialog", when// dismissing in thread.// This is because Activity has to manage its dialog during onPause() and onResume() to restore// dialogs' state. So if you manually dismiss it in onDestroy(), it will cause JE.

}}


本文标签: 调用 形式