Open
Description
- 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:
- Make the
MainActivity
singleTask, and don't callfinish
, just send it to background - Enable Firebase Analytics debug, and open the DebugView
- Push a notification to the device
- Make sure we can see the notification_receive event in the DebugView
- Tap the notification to open the App
- 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);
}
}