Skip to content

notification_open never reported if onCreate of MainActivity was not called #3799

Open
@kevin-zqw

Description

@kevin-zqw
  • Android Studio version: Android Studio Chipmunk | 2021.2.1
  • Firebase Component: Firebase Cloud Messaging
  • Component version: 23.0.5

Problems

My app has only one MainActivity, and it's singleTask.
When I received the notification and tap it to bring my app to foreground, the MainActivity was not recreated and its onCreate method was not called.
So FcmLifecycleCallbacks had no chance to report the notification_open event.

Steps to reproduce:

  1. Make the MainActivity singleTask, and don't call finish, just send it to background
  2. Enable Firebase Analytics debug, and open the DebugView
  3. Push a notification to the device
  4. Make sure we can see the notification_receive event in the DebugView
  5. Tap the notification to open the App
  6. notification_open event won't show in the DebugView

Relevant Code:

FcmLifecycleCallbacks
code below will never be called

  @Override
  public void onActivityCreated(Activity createdActivity, Bundle instanceState) {
    Intent startingIntent = createdActivity.getIntent();
    if (startingIntent == null || !seenIntents.add(startingIntent)) {
      // already seen (and logged) this, no need to go any further.
      return;
    }

    if (VERSION.SDK_INT <= VERSION_CODES.N_MR1) {
      // On Android 7.1 and lower Bundle unparceling is not thread safe. Wait to log notification
      // open after Activity.onCreate() has completed to try to avoid race conditions with other
      // code that may be trying to access the Intent extras Bundle in onCreate() on a different
      // thread.
      new Handler(Looper.getMainLooper()).post(() -> logNotificationOpen(startingIntent));
    } else {
      logNotificationOpen(startingIntent);
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions