How to open a Deep Link with an activity on BackStack if the app is not opened

20 Views Asked by At

I have a deep link to a transparent activity that interacts with the Play Billing Library (opens the system purchase bottom sheet).

There are two situations in which this deep link can be opened:

  • when the app is opened, or;
  • when the app is not opened.

If the app is not opened I want to add the "HomeActivity" to the backstack before executing any other action.

What is the most correct way to do that?

1

There are 1 best solutions below

0
Andrew On

You can achieve this by handling the deep link in your app's manifest file and specifying the appropriate launch mode for the transparent activity to be opened. You can also consider using TaskStackBuilder to manage the back stack. Here's a sample code snippet:

<activity
    android:name=".YourTransparentActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="yourdeeplink" />
    </intent-filter>
</activity>

For more details, you can refer to the Android developer documentation on handling deep links: Handle Deep Links

Also, check out the TaskStackBuilder documentation for managing the back stack: TaskStackBuilder