Skip to content

[Starfish] Use a better way to determine app foreground launch #3084

@markushi

Description

@markushi

Description

Instead of checking for process foreground like we did earlier

instance.appLaunchedInForeground = ContextUtils.isForegroundImportance();

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);
});

Metadata

Metadata

Labels

No labels
No labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions