Skip to content

Commit b6ee2a2

Browse files
author
Craig Mautner
committed
Use correct WindowManager for Toast.
The WindowManager retrieved from the activity Context with getSystemService is incorrect for a Toast. Because it contains a parent window when addView is called its LayoutParams.token is set to the value of the parent window. Then when an Activity is dismissed WindowManagerGlobal.closeAll() sees the incorrect token and incorrectly closes the Toast. This fix uses the application Context instead of the activity Context to retrieve a WindowManager with no parent window. This leaves the token unchanged and keeps from dismissing the toast when the activity is closed. Fixes bug 7048792. Change-Id: I92c3095d8fabd6e9e4206e9bc8e917885ab322a9
1 parent ac137b3 commit b6ee2a2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

core/java/android/widget/Toast.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ static private INotificationManager getService() {
305305

306306
private static class TN extends ITransientNotification.Stub {
307307
final Runnable mShow = new Runnable() {
308+
@Override
308309
public void run() {
309310
handleShow();
310311
}
311312
};
312313

313314
final Runnable mHide = new Runnable() {
315+
@Override
314316
public void run() {
315317
handleHide();
316318
// Don't do this in handleHide() because it is also invoked by handleShow()
@@ -329,7 +331,7 @@ public void run() {
329331

330332
View mView;
331333
View mNextView;
332-
334+
333335
WindowManager mWM;
334336

335337
TN() {
@@ -350,6 +352,7 @@ public void run() {
350352
/**
351353
* schedule handleShow into the right thread
352354
*/
355+
@Override
353356
public void show() {
354357
if (localLOGV) Log.v(TAG, "SHOW: " + this);
355358
mHandler.post(mShow);
@@ -358,6 +361,7 @@ public void show() {
358361
/**
359362
* schedule handleHide into the right thread
360363
*/
364+
@Override
361365
public void hide() {
362366
if (localLOGV) Log.v(TAG, "HIDE: " + this);
363367
mHandler.post(mHide);
@@ -370,7 +374,8 @@ public void handleShow() {
370374
// remove the old view if necessary
371375
handleHide();
372376
mView = mNextView;
373-
mWM = (WindowManager)mView.getContext().getSystemService(Context.WINDOW_SERVICE);
377+
mWM = (WindowManager)mView.getContext().getApplicationContext()
378+
.getSystemService(Context.WINDOW_SERVICE);
374379
// We can resolve the Gravity here by using the Locale for getting
375380
// the layout direction
376381
final Configuration config = mView.getContext().getResources().getConfiguration();

0 commit comments

Comments
 (0)