Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deep link into an app while the app is already running in the background

I have implemented a DeeplinkActivity to catch the intent-filter data scheme and open an activity. The issue I am having is the app is already open in the background and then the user clicks a deep link to open the home screen activity. If the user presses back to get out of the app it will go to what was running in the background. I wanted it to just back out of the app.

I have tried this.

        Intent intent = new Intent(this, LaunchActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
        startActivity(intent);

But this does not work. Any suggestions?

like image 347
DDukesterman Avatar asked Sep 15 '14 21:09

DDukesterman


1 Answers

I have just had this problem fixed myself.

First you need to go to the manifest and set launchMode to "singleTask", this will prevent your app from opening a new instance entirely.

Second you need to go the Activity that's accepting that intent filter and override this method

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
}

now by using the new intent here you will have access to the deep link and be able to route to where you need to within your app.

like image 150
Mahmoud Omara Avatar answered Nov 12 '22 13:11

Mahmoud Omara