androiddeep-linkingintentfilterdeeplink

Start activity from deeplink and on back press resume from latest running activity


I am handling deep links in my app. When a link in the email is clicked, it opens related activity in the app. On back press, it either goes back to email or home (up to intent flags i use). I need it to go back to latest running activity(if the app was being used before clicking the link in email) or(else) go to first activity to restart the app.

To be clearer: User is on activity C. Email notification comes, checks it and clicks the link inside. It opens up activity E. Here, if user back press, I want to end current task and resume activity C - if activity C task has not been killed by the system. If killed, go to activity A.

Without intent flags, it creates a new task(second app instance) and on back press it goes back to email client. With NEW_TASK flag, a new tasks starts. If I use CLEAR_TASK flag with this, on back press it goes home.

Manifest

<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="www.mysite.com"
                    android:pathPattern="/mypath/*" />
</intent-filter>

FirstActivity

if(getIntent().getData().toString().contains("keyword")){
       //intent.setFlags(...);
       intent.putExtra("myextra", getIntent().getData().toString());
   }
    startActivity(intent);
    finish();

EmailResultActivity

 String data = getIntent().getExtras().getString("myextra");

Solution

  • To achieve this you need to handle deep-link from a common activity. (Eg: If your app has a common activity say XYZ. Then every deep-link should come to XYZ activity and then according to parameters of deep-link, you should move to respective screen) Also you need to make XYZ as singleTask.