Skip to content

Commit

Permalink
changed AppStartMetrics to use ActivityLifecycleCallbacksAdapter
Browse files Browse the repository at this point in the history
added app launch foreground check to AppStartMetrics ctor
  • Loading branch information
stefanosiano committed Jul 10, 2024
1 parent c2b6daa commit 31d9b25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
8 changes: 1 addition & 7 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public class io/sentry/android/core/performance/ActivityLifecycleTimeSpan : java
public final fun getOnStart ()Lio/sentry/android/core/performance/TimeSpan;
}

public class io/sentry/android/core/performance/AppStartMetrics : android/app/Application$ActivityLifecycleCallbacks {
public class io/sentry/android/core/performance/AppStartMetrics : io/sentry/android/core/performance/ActivityLifecycleCallbacksAdapter {
public fun <init> ()V
public fun addActivityLifecycleTimeSpans (Lio/sentry/android/core/performance/ActivityLifecycleTimeSpan;)V
public fun clear ()V
Expand All @@ -442,12 +442,6 @@ public class io/sentry/android/core/performance/AppStartMetrics : android/app/Ap
public fun getSdkInitTimeSpan ()Lio/sentry/android/core/performance/TimeSpan;
public fun isAppLaunchedInForeground ()Z
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityDestroyed (Landroid/app/Activity;)V
public fun onActivityPaused (Landroid/app/Activity;)V
public fun onActivityResumed (Landroid/app/Activity;)V
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityStarted (Landroid/app/Activity;)V
public fun onActivityStopped (Landroid/app/Activity;)V
public static fun onApplicationCreate (Landroid/app/Application;)V
public static fun onApplicationPostCreate (Landroid/app/Application;)V
public static fun onContentProviderCreate (Landroid/content/ContentProvider;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* transformed into SDK specific txn/span data structures.
*/
@ApiStatus.Internal
public class AppStartMetrics implements Application.ActivityLifecycleCallbacks {
public class AppStartMetrics extends ActivityLifecycleCallbacksAdapter {

public enum AppStartType {
UNKNOWN,
Expand Down Expand Up @@ -76,6 +76,7 @@ public AppStartMetrics() {
applicationOnCreate = new TimeSpan();
contentProviderOnCreates = new HashMap<>();
activityLifecycles = new ArrayList<>();
appLaunchedInForeground = ContextUtils.isForegroundImportance();
}

/**
Expand Down Expand Up @@ -223,7 +224,8 @@ public static void onApplicationCreate(final @NotNull Application application) {
if (instance.applicationOnCreate.hasNotStarted()) {
instance.applicationOnCreate.setStartedAt(now);
application.registerActivityLifecycleCallbacks(instance);
instance.appLaunchedInForeground = ContextUtils.isForegroundImportance();
instance.appLaunchedInForeground =
instance.appLaunchedInForeground || ContextUtils.isForegroundImportance();
new Handler(Looper.getMainLooper())
.post(
() -> {
Expand Down Expand Up @@ -255,24 +257,6 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
}
}

@Override
public void onActivityStarted(@NonNull Activity activity) {}

@Override
public void onActivityResumed(@NonNull Activity activity) {}

@Override
public void onActivityPaused(@NonNull Activity activity) {}

@Override
public void onActivityStopped(@NonNull Activity activity) {}

@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {}

@Override
public void onActivityDestroyed(@NonNull Activity activity) {}

/**
* Called by instrumentation
*
Expand Down

0 comments on commit 31d9b25

Please sign in to comment.