androiddeep-linkingurbanairship.com

Android 8.0+ Deep Linking Opens Launcher Activity First Only When App was Killed


On Android 8.0+ only, when opening my app with a deep link (clicking on the push notification with a URI attached) the app will open my entrypoint activity and then open up the deep linking activity.

This is not seen on Android lower than 8.0. In that case, it will open the deep linking activity directly and it will not open the splash screen activity.

Unfortunately, the way the app works is that when the entrypoint activity is called (it is a splash screen) it will then move to another activity. This makes it highly unreliable to open the deep link when the app was hard closed because when the deep link activity runs (approximately 80ms after the splash screen runs) the app is already transitioning to the next activity which may cancel out the deep link entirely.

To circumvent this, I've tried to handle the deep linking inside of the splash activity with setting the launchMode to singleTask, singleTop and singleInstance. Unfortunately, none of those worked.

I've managed to solve this issue by using a timer by holding the splash screen for 200ms longer than usual but that solution seems dirty and doesn't seem extremely reliable for all devices.

Here is the my splash activity and the deep linking activity in the manifest

<activity
 android:name=".activities.LauncherActivity"
 android:excludeFromRecents="true"
 android:taskAffinity="${launcherAffinity}"
 android:theme="@android:style/Theme.Translucent.NoTitleBar">
 <intent-filter>
    <action android:name="android.intent.action.MAIN" />

     <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>


<activity
 android:name=".activities.ParseDeepLinkActivity"
 android:theme="@android:style/Theme.NoDisplay">
 <intent-filter>
  <action android:name="android.intent.action.VIEW" />

   <data
     android:host="*"
     android:scheme="com.deeplink" />

     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />
  </intent-filter>
  <intent-filter>
   <action android:name="android.intent.action.VIEW" />

     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />

        <data
         android:scheme="https"
         android:host="deep.link.net"
         android:pathPrefix="/mobile" />
  </intent-filter>
</activity>

This is my launcher activity

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        startActivity(
                new Intent(this, LoginActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        finish();
    }

I would like it if I can just open the deep link activity directly as it does on lower than 8.0. I tried searching for any documentation if deep linking has changed in 8.0+ but there was nothing I could find.


Solution

  • Solved!

    The issue was in UrbanAirship. Our class that extends AirshipReceiver in the method onNotifactionOpened was default returning false which means it will also launch the launcher activity. Why this causes an issue in only 8.0+ I am not too sure. Here is how I resolved it

     @Override
        protected boolean onNotificationOpened(@NonNull Context context, @NonNull NotificationInfo notificationInfo) {
            Map<String, ActionValue> notificationActions = notificationInfo.getMessage().getActions();
            // Return false here to allow Urban Airship to auto launch the launcher activity
            try{
                return notificationActions.containsKey("^d");
            }catch(Exception e){
                return false;
            }
        }
    

    ^d is the default key for deep link actions as listed here https://docs.airship.com/reference/libraries/android/latest/reference/com/urbanairship/actions/DeepLinkAction.html