Recommendation for Deep links in Android

Recommendation for Deep links in Android

Observation:

Deep linking can bring the issue of "duelling activities". The concerning condition is deep-linking into an app that uses a multiple activity stack, where the root activity has no content (e.g. using launch activity to enforce an authentication strategy).

Most applications whose main activity uses the "standard" or "singleTopactivity launch mode will have, any time a deep link is clicked, a second instance. That instance of your activity will open in the app that hosts the link. Then there can be two (potentially) full-fledged versions of an app running in two different tasks.


Proposed solution:

Introduce a new activity whose only function is to manage deep links. This allows the launch activity to remain single top. To do so explicitly create a new activity (e.g. .IntentForwardActivity), define the launchMode as "singleTask" and add the intent-filters for deep links (e.g. android:scheme). When the new activity receives a deep-linking intent, it forwards it to your launch activity, and the deep link behaves as expected.

Example:


Notice that this new activity does not contain the launcher-activity intent filter. For this solution to work, it's important to keep your launch activity and deep-link-receiving activity separate. If you have a launch activity that's already "singleTop," you shouldn't have to change it at all.

Because the activity is not created every time (single instance), you'll have to forward the intents from both onCreate() and onNewIntent()Let's see some sample code:


This solution is simple and effective, and requires no changes of existing app infrastructure.

 

References:


    • Related Articles

    • Android 10 and MOCA SDK

      MOCA Android SDK has been tested in the Android 10 OTA. Find the notes for this version below: Android 10 introduces a new permission model where the user can choose between “When in Use” or “Always” location permission. The SDK works correctly with ...
    • Android Permissions Detailed for MOCA SDK

      The MOCA SDK requests a variety of permissions, some of them being optional. Here is a breakdown of each permission and their effect on the SDK:   Permission Explanation android.permission.INTERNET Allows MOCA SDK to open network sockets so it has ...
    • Android Studio Instant Run and MOCA SDK

      It is recommended to turn off Instant Run in Android Studio. Instant Run uses portions of the SDK that might not be necessary for your integration and give you false error and warning messages.   Example stack trace when using Instant Run: I/art: ...
    • My Android app does not detect beacons?

      Beacon detection troubleshooting is divided in three steps: SDK configuration, device configuration and MOCA Console configuration.   1. MOCA SDK requires the following configuration checks in the MOCA.properties file: Flag proximityService is ...
    • MOCA iOS SDK LOG_LEVEL Settings

      You can set a variety of logging levels for our SDK in the MOCAconfig.plist file, under the LOG_LEVEL variable:   LOG_LEVEL Description Off Log is turned off at SDK level. Error Shows only error events. Warning Shows only warning events. Info Shows ...