Closed
Description
Expected Behavior
App should not crash.
Current Behavior
App is crashing with the following stacktrace:
java.lang.RuntimeException: Can't create handler inside thread Thread[DefaultDispatcher-worker-1,5,main] that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:227)
at android.os.Handler.<init>(Handler.java:129)
at android.view.GestureDetector$GestureHandler.<init>(GestureDetector.java:310)
at android.view.GestureDetector.<init>(GestureDetector.java:425)
at android.view.GestureDetector.<init>(GestureDetector.java:402)
at com.amplitude.android.internal.gestures.AutocaptureWindowCallback.<init>(AutocaptureWindowCallback.kt:19)
at com.amplitude.android.utilities.DefaultEventUtils.startUserInteractionEventTracking(DefaultEventUtils.kt:146)
at com.amplitude.android.plugins.AndroidLifecyclePlugin.onActivityResumed(AndroidLifecyclePlugin.kt:113)
at com.amplitude.android.plugins.AndroidLifecyclePlugin$setup$1.invokeSuspend(AndroidLifecyclePlugin.kt:65)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:832)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@638111d, Dispatchers.Default]
Possible Solution
Possibly, GestureDetector is initialized too early. The error occurs only in version 1.19.3
, indicating that PR 232 changed some behavior.
Steps to Reproduce
@OptIn(ExperimentalAmplitudeFeature::class)
@Singleton
class AmplitudeAnalytics @Inject constructor(@ApplicationContext context: Context) : Analytics {
private val analytics: Amplitude
init {
val trackingOptions = TrackingOptions()
trackingOptions.disableCity().disableIpAddress().disableLatLng()
analytics = Amplitude(
Configuration(
apiKey = "your-api-key",
context = context,
trackingOptions = trackingOptions,
autocapture = autocaptureOptions {
+sessions
+appLifecycles
+elementInteractions
}
)
)
}
}
Environment
Any Android device
Metadata
Metadata
Assignees
Labels
No labels