LGSnackbar icon indicating copy to clipboard operation
LGSnackbar copied to clipboard

android.view.WindowManager$BadTokenException in Nougat

Open abhinashpati opened this issue 7 years ago • 10 comments

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.

abhinashpati avatar Aug 01 '17 06:08 abhinashpati

Thanks for reporting. I'll investigate on it.

loregr avatar Aug 05 '17 11:08 loregr

I have the same problem.

nontravis avatar Aug 19 '17 05:08 nontravis

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?

loregr avatar Aug 19 '17 11:08 loregr

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

akexorcist avatar Aug 19 '17 12:08 akexorcist

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.

alfco333 avatar Nov 18 '17 00:11 alfco333

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?

jsimoes84 avatar Sep 03 '18 16:09 jsimoes84

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.

aruljey avatar Sep 25 '18 11:09 aruljey

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...

thiyagesh6m avatar Dec 08 '18 10:12 thiyagesh6m

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

GlaucioOliveira avatar Dec 10 '20 20:12 GlaucioOliveira

this bug no fix yet?

Hendriyawan avatar Aug 29 '21 09:08 Hendriyawan