sentry-java
sentry-java copied to clipboard
[Starfish] Use a better way to determine app foreground launch
Description
Instead of checking for process foreground like we did earlier https://github.com/getsentry/sentry-java/blob/d43311af4de9697012a932ff860c9f2b2ff3d3e0/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java#L136
we could use a similar approach as firebase.
In simplified terms this would looks like the following:
final AtomicBoolean anyActivityCreated = new AtomicBoolean(false);
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacksAdapter() {
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
super.onActivityCreated(activity, savedInstanceState);
anyActivityCreated.set(true);
unregisterActivityLifecycleCallbacks(this);
}
});
new Handler(Looper.getMainLooper()).post(() -> {
final boolean isForegroundAppLaunch = anyActivityCreated.get();
Log.e(TAG, "onCreate: isForegroundAppLaunch: " + isForegroundAppLaunch);
});