Search code examples
androidnotificationsandroid-12

Notification: Open different Activities dynamically on Android 12 - trampoline restrictions issue


Similar question: Android 12 - Notification trampoline restrictions

My question is slightly different from the above question because I am asking for a fundamental proper way to handle the deeplinks.

I am displaying the notification triggered by the Push notification. If the app is Multi-Activity architecture and the app needs to open different Activity depends on the deeplink value, then there are 2 ways to handle:

  1. Interpret the deeplink value first and then register the proper Activity when clicked.
  2. Use a transparent dummy Activity as the destination. Have the TransparentDeeplinkHandleActivity::class.java to handle which Activity to open.

I am an SDK developer which makes it slightly more complicated. I don't know the client's destination Activity class and if they are using Multi-Activity or Single-Activiy-multi-Fragment architecture.

Solution 2 sounds a bit hacky. Should I implement the callback to ask the client-side to return the destination Activity class given the deeplink path?


Solution

  • Answering my own question.

    I ended up choosing Solution #2, which is the hacky solution:

    1. Use a transparent dummy Activity as the destination. Have the TransparentDeeplinkHandleActivity::class.java to handle which Activity to open.

    The reason is that SDK needs to send the analytics before opening the client's "real" Activity.

    Pre-Android 12, the SDK is architected to open the BroadCastRecevier and it sends analytics. And then the BroadCastReceiver opens the Activity.

    The BroadCastRecevier is now replaced with TransparentDeeplinkHandleActivity for TargetSDK >= 31