Skip to content

Commit 89fc3ac

Browse files
committed
Bug 5513073 - IllegalArgumentException: View not attached to window
manager Remove extra queued dialog dismiss messages when applicable. Log an error if the app tries to dismiss a dialog when its window has been destroyed. Change-Id: Ice8383d4420c052e31fbbd9fcd25051f3bd9b58d
1 parent ad41a94 commit 89fc3ac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/java/android/app/Dialog.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.os.Bundle;
2929
import android.os.Handler;
3030
import android.os.Message;
31+
import android.util.Log;
3132
import android.util.TypedValue;
3233
import android.view.ActionMode;
3334
import android.view.ContextMenu;
@@ -77,6 +78,7 @@
7778
*/
7879
public class Dialog implements DialogInterface, Window.Callback,
7980
KeyEvent.Callback, OnCreateContextMenuListener {
81+
private static final String TAG = "Dialog";
8082
private Activity mOwnerActivity;
8183

8284
final Context mContext;
@@ -300,15 +302,21 @@ public void dismiss() {
300302
if (Thread.currentThread() != mUiThread) {
301303
mHandler.post(mDismissAction);
302304
} else {
305+
mHandler.removeCallbacks(mDismissAction);
303306
mDismissAction.run();
304307
}
305308
}
306309

307-
private void dismissDialog() {
310+
void dismissDialog() {
308311
if (mDecor == null || !mShowing) {
309312
return;
310313
}
311314

315+
if (mWindow.isDestroyed()) {
316+
Log.e(TAG, "Tried to dismissDialog() but the Dialog's window was already destroyed!");
317+
return;
318+
}
319+
312320
try {
313321
mWindowManager.removeView(mDecor);
314322
} finally {

0 commit comments

Comments
 (0)