summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/widget/Toast.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java
index 485bd37a266e..ab361390fdef 100644
--- a/core/java/android/widget/Toast.java
+++ b/core/java/android/widget/Toast.java
@@ -374,8 +374,13 @@ 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();
+ if (context.getApplicationContext() != null) {
+ // Use application context, except when called from system
+ // service where there is no application context.
+ context = context.getApplicationContext();
+ }
+ 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();