Skip to content

Android: $push_notification_opened not captured on a notification tap #558

Description

@turnipdabeets

Bug description

$push_notification_opened is never captured on Android. This is the Android counterpart to #555, which reported the same symptom on iOS.

The native SDK reads a notification tap from the launch Activity's intent in onActivityCreated, and install() only registers lifecycle callbacks — it never seeds from an Activity that already exists:

  • posthog-android/src/main/java/com/posthog/android/internal/PostHogActivityLifecycleCallbackIntegration.ktonActivityCreated(), install()

In a Flutter app the SDK installs too late to see that callback. Measured in the example app on a Pixel 9 emulator:

17:54:27.516  MainActivity.onCreate
17:54:27.939  onCreate END / onStart / onResume   <- all three complete
17:54:28.582  first PostHog event                 <- SDK installs ~640ms later

Every lifecycle callback for the launch Activity is missed. com.posthog.posthog.AUTO_INIT does not help either — plugin registration still runs inside Activity.onCreate, after the framework has dispatched onActivityCreated. This differs from iOS, where AUTO_INIT does win the race.

Separately, a tap that arrives while the app is already running is delivered to Activity.onNewIntent. Application.ActivityLifecycleCallbacks has no onNewIntent hook, so no library can observe it — the host application, or the Flutter plugin, has to forward it.

How to reproduce

  1. Flutter app with posthog_flutter, configured from Dart with Posthog().setup(config).
  2. Cold-launch it from a notification tap (or adb shell am start -n <pkg>/.MainActivity -e google.message_id "test").
  3. Observe $screen is captured and $push_notification_opened is not.

For the warm-start case, background the app and deliver the intent to the live process (-f 0x20000000).

Expected behavior

A notification tap is captured as $push_notification_opened on Android, on a cold launch and while the app is already running, matching iOS.

Native apps that call PostHogAndroid.setup() from Application.onCreate are unaffected for cold start — the integration is registered before the launch Activity is created. The gap is specific to hosts that configure the SDK from their own runtime.

Related

Per-SDK status:

Additional context

Found while investigating #555. Push support shipped in posthog_flutter 5.35.0 (#511); cold-start capture has never worked on Flutter on either platform since then. #511 forwarded the config correctly — its tests assert that the flags reach native — but the automatic capture depends on the SDK being installed before the OS delivers the tap, which no unit test on either side of the bridge can observe.

This is not about token registration, which works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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