1

Usually I know how to deal with this type of error - but in this case it is happening in my app but not originating in my code - really missing a entry-point on where to look there ..

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@40fd04c8 is not valid; is your activity running?
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2806)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
ligi
  • 39,001
  • 44
  • 144
  • 244
  • Please check http://stackoverflow.com/questions/7811993/error-binderproxy45d459c0-is-not-valid-is-your-activity-running?lq=1 and http://stackoverflow.com/questions/9529504/unable-to-add-window-token-android-os-binderproxy-is-not-valid-is-your-activ – Rajesh Jadav Aug 24 '15 at 12:35
  • @RajeshJadav these are cases that originate in the app-code - I know how to deal with them - just not when the crash does not originate in my own code – ligi Aug 24 '15 at 12:49

2 Answers2

0

You should insure your activity is active,which should be the first of activty stack.

simonws
  • 65
  • 5
0

You can try like this:

 private boolean isTopActivity(String packageName) 
{
ActivityManager _am = (ActivityManager)   context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> list = _am.getRunningAppProcesses();
if(list.size() == 0) return false;
for(ActivityManager.RunningAppProcessInfo process:list)
{
    Log.d(getTAG(),Integer.toString(process.importance));
    Log.d(getTAG(),process.processName);
    if(process.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND &&
            process.processName.equals($packageName))
    {
        return true;
    }
}
return false;

}

simonws
  • 65
  • 5
  • Can you give some background / context? Not even sure where I should put this and what to do according to the result of this function – ligi Aug 25 '15 at 08:11