From 54ae2f389cd0d9b9a558b5f61e096aec6215966b Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Wed, 5 Dec 2012 09:49:57 -0800 Subject: Fix NPE when showing Toast from system process. The system process has no ApplicationContext and consequently was returning null. Use the base Context in these cases. Bug 7673699 fixed. Change-Id: Ie2ab856bb0baefff44775a12bef7802320f72656 --- core/java/android/widget/Toast.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'core/java/android/widget/Toast.java') diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java index 485bd37..1d85126 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -374,8 +374,11 @@ public class Toast { // remove the old view if necessary handleHide(); mView = mNextView; - mWM = (WindowManager)mView.getContext().getApplicationContext() - .getSystemService(Context.WINDOW_SERVICE); + Context context = mView.getContext().getApplicationContext(); + if (context == null) { + context = mView.getContext(); + } + mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); // We can resolve the Gravity here by using the Locale for getting // the layout direction final Configuration config = mView.getContext().getResources().getConfiguration(); -- cgit v1.1