mixpanel/mixpanel-android

Tried to access visual service WindowManager from a non-visual Context

fredericojssilva opened this issue · 5 comments

Getting this exception even using activity context.

Sdk: 31

2021-12-15 16:00:33.917 3319-3319/com.fuze.fuzeapp E/ContextImpl: Tried to access visual service WindowManager from a non-visual Context:BaseApplication@fbc427e WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
    java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:com.fuze.fuzeapp.base.BaseFuzeApplication@fbc427e
        at android.app.ContextImpl.getSystemService(ContextImpl.java:2059)
        at android.content.ContextWrapper.getSystemService(ContextWrapper.java:857)
        at com.mixpanel.android.mpmetrics.SystemInformation.<init>(SystemInformation.java:91)
        at com.mixpanel.android.mpmetrics.SystemInformation.getInstance(SystemInformation.java:34)
        at com.mixpanel.android.mpmetrics.MPConfig.<init>(MPConfig.java:282)
        at com.mixpanel.android.mpmetrics.MPConfig.readConfig(MPConfig.java:545)
        at com.mixpanel.android.mpmetrics.MPConfig.getInstance(MPConfig.java:152)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.<init>(MixpanelAPI.java:388)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.getInstance(MixpanelAPI.java:649)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.getInstance(MixpanelAPI.java:535)
        at com.fuze.fuzeapp.util.mixpanels.MixPanelManager.makeMixpanelApiInstance(MixPanelManager.java:546)
        at com.fuze.fuzeapp.util.mixpanels.MixPanelManager.initMixpanelApi(MixPanelManager.java:536)
        at com.fuze.fuzeapp.util.mixpanels.MixPanelManager.initialize(MixPanelManager.java:493)

hi @fredericojssilva , which Mixpanel SDk version are you using?

@zihejia latest one. 5.9.6

hi @fredericojssilva , the issue is from the Mixpanel messages feature. On Jan 1, 2022, we’ll remove the Messages & Experiments feature from Mixpanel(more details). We will release 6.0.0 on that date as well which no longer contains Messages & Experiments feature. For now, if you don't want to wait, you can try 6.0.0-beta1.

Got it. Thanks for the update @zihejia

I'm still facing this problem with version 7.0.1

Can you please change how this works so that it doesn't require initializing inside an Activity? This makes writing good code very difficult, we need to log analytics even from background threads, and creating a single Mixpanel instance that can be used application wide is better. Requiring people to initialize this with an Activity context adds a lot of unnecessary pain.

Firebase Analytics does not have such limitations.