I have implemented deep linking in my app. I added this intent filter in my manifest file, and the deep linking is working.
I had this exact same problem, except I wanted the user to land back in the main task with the full back stack, as though they had just used the app switcher to move to my app. To accomplish this I had to reorder tasks.
1) Give my app permission to re-order tasks
2) Keep track of what the main task ID is
public class MainActivity {
public static int mainTaskId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super(savedInstanceState);
//set the main task ID
taskId = getTaskId();
}
}
3) When my deep link activity is launched it saves some data for use later and then brings the main task to the front
public class DeepLinkActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super(savedInstanceState);
//persist deep link data
Uri uri = intent.getData();
String action = intent.getAction();
saveForLater(uri, action);
if(isTaskRoot()){
//I'm in my own task and not the main task
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
activityManager.moveTaskToFront(MainActivity.taskId, ActivityManager.MOVE_TASK_NO_USER_ACTION);
}
}
}
}
4) When whatever activity is at the top of the main task's back stack starts, it checks if there's any saved data to work on, and works on it.