countly-sdk-android: java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context

App crash while app restart and tries to call

countly.onStart(activity)

Error:

Tried to access visual service WindowManager from a non-visual Context:com.company.product.messages.app.MessagesApp@ee05bed 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.company.product.messages.app.MessagesApp@ee05bed at android.app.ContextImpl.getSystemService(ContextImpl.java:2207) at android.content.ContextWrapper.getSystemService(ContextWrapper.java:934) at ly.count.android.sdk.DeviceInfo$1.getResolution(DeviceInfo.java:127) at ly.count.android.sdk.DeviceInfo.getCommonMetrics(DeviceInfo.java:550) at ly.count.android.sdk.DeviceInfo.getMetrics(DeviceInfo.java:592) at ly.count.android.sdk.ModuleSessions.beginSessionInternal(ModuleSessions.java:42) at ly.count.android.sdk.Countly.onStart(Countly.java:836) at com.company.product.messages.common.analytics.AnalyticsManagerImpl.onActivityStart(AnalyticsManager.kt:93) at com.company.product.messages.common.core.utils.MainActivityHelper$initialize$5.onStateChanged(MainActivityHelper.kt:88) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.jvm.kt:320) at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.jvm.kt:257) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.jvm.kt:293) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.jvm.kt:142) at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.jvm.kt:124) at androidx.lifecycle.ReportFragment$Companion.dispatch$lifecycle_runtime_release(ReportFragment.android.kt:190) at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.android.kt:119) at android.app.Activity.dispatchActivityPostStarted(Activity.java:1476) at android.app.Activity.performStart(Activity.java:8693) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3847) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:225) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:205) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:187) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2468) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8248) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Hello @almozavr,

The SDK is capable of extracting that information, but StrictMode explicitly logs it. Just to confirm, are you seeing the correct values on your end? The necessary data is being captured, and we’ll review this behavior for potential adjustments in the future.

Thank you so much for your understanding 🙌

@arifBurakDemiray Thanks a lot for sharing insight and very quick answer!

We are sorry that documentation is not in the latest form @gopidholakia 🙇

Yes, if application class is provided in the configuration, Countly Android SDK will handle all onStart and onStop calls of the Activities of the App.

Please have a look at our example app’s App class https://github.com/Countly/countly-sdk-android/blob/master/app/src/main/java/ly/count/android/demo/App.java

And MainActivity class, https://github.com/Countly/countly-sdk-android/blob/master/app/src/main/java/ly/count/android/demo/MainActivity.java

Again, we are sorry for the documentation is not in the latest form. We will update it as soon as possible. Thank you so much for your understanding 🙌

Happy coding 👋