1

I tried to run my app in an genymotion emulator however this is the error that I always get.

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.danicaabinuman.workforce, PID: 2087
  android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@7ee39fa is not valid; is your activity running?
      at android.view.ViewRootImpl.setView(ViewRootImpl.java:679)
      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
      at android.widget.Toast$TN.handleShow(Toast.java:434)
      at android.widget.Toast$TN$2.handleMessage(Toast.java:345)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6119)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

I tried to run my app to an android mobile and the error did not occur. My app works perfectly fine. Please help me.

user1506104
  • 6,554
  • 4
  • 71
  • 89
  • This kind of error is not related to emulator and real device. This issue is concerned with activity life cycle management. I guess some where you are trying to show dialog from finished activity. Please provide more code. – SimpleCoder Jul 04 '18 at 03:12
  • For more info about this error please check similar answer on https://stackoverflow.com/a/18665887/3787344 – SimpleCoder Jul 04 '18 at 03:14
  • is it android 7.1 ? https://github.com/drakeet/ToastCompat – NitZRobotKoder Sep 03 '18 at 18:03

1 Answers1

1

It looks like you're trying to show a Toast after your activity has already been closed. Do you have a background thread or task that shows the Toast when it finishes? If so, you should check whether the activity has been destroyed prior to showing the toast, by calling isFinishing().

Dmitry Brant
  • 7,612
  • 2
  • 29
  • 47