Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AbstractMethodError when getting Lifecycle #2228

Merged
merged 9 commits into from
Sep 6, 2022
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.android.core;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.ProcessLifecycleOwner;
import io.sentry.IHub;
import io.sentry.Integration;
Expand Down Expand Up @@ -83,13 +84,25 @@ private void addObserver(final @NotNull IHub hub) {
if (this.options == null) {
return;
}

Lifecycle lifeCycle;

try {
lifeCycle = ProcessLifecycleOwner.get().getLifecycle();
} catch (AbstractMethodError e) {
options
.getLogger()
.log(SentryLevel.ERROR, "AppLifecycleIntegration failed to get Lifecycle.", e);
return;
}

watcher =
new LifecycleWatcher(
hub,
this.options.getSessionTrackingIntervalMillis(),
this.options.isEnableAutoSessionTracking(),
this.options.isEnableAppLifecycleBreadcrumbs());
ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher);
lifeCycle.addObserver(watcher);
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
options.getLogger().log(SentryLevel.DEBUG, "AppLifecycleIntegration installed.");
}

Expand Down