jmp-12 / SuperToasts

A library that extends the Android toast framework.
Apache License 2.0
2.67k stars 499 forks source link

Does not work with Android O #108

Open alexeyvasilyev opened 7 years ago

alexeyvasilyev commented 7 years ago

Toasts crashed if the project is targeting Android O.

com.github.johnpersano.supertoasts.demo E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                       Process: com.github.johnpersano.supertoasts.demo, PID: 6077
                                                                                       android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
                                                                                           at android.view.ViewRootImpl.setView(ViewRootImpl.java:760)
                                                                                           at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
                                                                                           at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
                                                                                           at com.github.johnpersano.supertoasts.library.Toaster.displaySuperToast(Toaster.java:186)
                                                                                           at com.github.johnpersano.supertoasts.library.Toaster.handleMessage(Toaster.java:136)
                                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                           at android.os.Looper.loop(Looper.java:156)
                                                                                           at android.app.ActivityThread.main(ActivityThread.java:6440)
                                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                                           at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:746)

To reproduce recompile demo with following and run on emulator

    compileSdkVersion 'android-O'
    buildToolsVersion '26.0.0-rc1'
    minSdkVersion 16
    targetSdkVersion 'O'
lambed commented 6 years ago

After year so using SuperToast I am now having the same problem when my project is using O. Any suggestions would be greatly appreciated.

lockeb commented 6 years ago

In the same position. Doesn't look like this library is going to be fixed so I switched to https://github.com/Muddz/StyleableToast. It works almost the same and is compatible with Android O.

MatheusDinni commented 6 years ago

I had the same issue. Just use SuperActivityToast instead of SuperToast and it works fine.