loregr / LGSnackbar

An easy to use and customisable wrapper of the native Android Snackbar which stays visible across multiple activities.
MIT License
47 stars 3 forks source link

android.view.WindowManager$BadTokenException in Nougat #2

Open abhinashpati opened 7 years ago

abhinashpati commented 7 years ago

android.view.WindowManager$BadTokenException: Unable to add window -- token null 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 greco.lorenzo.com.lgsnackbar.core.LGSnackbarPresenter.show(LGSnackbarPresenter.java:51) at greco.lorenzo.com.lgsnackbar.core.LGSnackbar.show(LGSnackbar.java:90) at greco.lorenzo.com.lgsnackbar.LGSnackbarManager.showSnackbar(LGSnackbarManager.java:91) at greco.lorenzo.com.lgsnackbar.LGSnackbarManager.show(LGSnackbarManager.java:86) at greco.lorenzo.com.lgsnackbar.LGSnackbarManager.show(LGSnackbarManager.java:70)

I'm only getting this on Android 7 or above devices. Below 7, it's working fine.

loregr commented 7 years ago

Thanks for reporting. I'll investigate on it.

nontravis commented 7 years ago

I have the same problem.

loregr commented 7 years ago

I am not able to replicate it, I've just run the example in the repo and it is working on a Nougat device. Could you please check if the example is working for you?

akexorcist commented 7 years ago

screenshot_20170819-193244

It look like the problem is about the solution that you use in this library. The library add the view to window manager directly so it doesn't minimized when user minimized the app. That's different with Snackbar library from Android Design Support Library because they use layout in each activity to add the Snackbar's view (Snackbar at findSuitableParent(View view)).

I think this can make the problem occur in some device firmware. As I tested with example in the repo, it work fine on Samsung Galaxy S8 and Moto Z but won't work with Android One

alfco333 commented 7 years ago

I have investigated a little on this topic and it seems some devices have to ask for this permission: SYSTEM_ALERT_WINDOW, but it can only be achieved through the Settings, I've used this intent for the task: new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName)); but some devices do not respond to the intent.

jsimoes84 commented 6 years ago

Hey there. Did you manage to fix this bug? I really like this project, but can't use it from android 7 above. Can you fix it?

aruljey commented 6 years ago

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

Hi loregr

Could you please solve this problem? I need this library to work with my APP.

thiyagesh6m commented 5 years ago

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? same problem brother please resolve it ... as of now any solution there...

GlaucioOliveira commented 3 years ago

Well, it's 2020 and this same problem continues... No fix to this?

Hendriyawan commented 3 years ago

this bug no fix yet?