Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-open (or resume) previously launched activity from a url link (deep link)?

I'm using deep linking to open my app this is the intent filter:

        <intent-filter>
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:host="myapp.delivery" />
            <data android:pathPattern="/.*" />

            <action android:name="android.intent.action.VIEW" />

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

Our use case is:

  1. user open apps, browses some restaurant
  2. user clicks restaurant (openning MenuActivity an activity with the restaurants menu)
  3. user click on a menu category for example Pizzas or Desserts or Soups, which opens the CategoryActivity.
  4. user clicks on a Dish to add to shopping cart I need to send an email with a url to the user.

My problem:

(Following step 4) User clicks url on email app (say gmail or inbox app) which prompts user with dialog to open my app or browser like this:

enter image description here

When user clicks to open with my app what happens is that the GotEmailActivity is opened on top of gmail app, I need it to open on top of previously opened instance of my app.

As you can see here 2 instances of my app are open (the first instance of app and the second instance is open on top of gmail),:

enter image description here

How to open clicked link in my previously launched app not on top of gmail/inbox app?

like image 797
Jeka Avatar asked Dec 28 '15 20:12

Jeka


People also ask

How do I access a deep link?

Adjust Deeplink Generator To use the tool, log in to your Adjust dashboard and open the Menu, where you'll see the 'Deeplink Generator' as an option. Click to open, and you'll find a page to input the information required to create your deep link. Then simply copy and paste into whichever campaign you've set up.

How do I open an app in deep link?

Select Open deep link URL in a browser option. Click Next. For Android, select Open the deep link in your Android app. Then select your app from the dropdown, in this case the com.

What is deep link in URL?

A type of destination URL in an ad that takes people to a specific page in an app. The following types of deep links are supported by Google Ads: Custom schemes: Custom schemes are custom URIs you can create to link to any in-app content.


2 Answers

Answer I found to work

So I created EntryActivity which is launched on top of gmail/inbox app:

public class EntryActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.entry_activity);

        Uri uriParams = getIntent().getData();

        Log.e("EntryActivity", uriParams.getHost() );
        Log.e("EntryActivity", uriParams.getQueryParameter("uid") + " " + uriParams.getQueryParameter("type") + " " + uriParams.getQueryParameter("token") );


        Intent startCategory = new Intent(this, GotEmailActivity.class);
        startCategory.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startCategory);
        this.finish();
    }

}

Now what is happening is that EntryActivity is opened ontop of Gmail app but it closes inmediatle but first launches GotEmailActivity which is already opened so attribute launchMode Singletop prevents a new instance of such activity.

Then when my app is opened at GotEmailActivity I send email to user with link to open app and GotEmailActivity has attribute android:launchMode="singleTop" in AndroidManifest so only 1 instance of it is opened:

    <!-- 
        Important: notice android:launchMode="singleTop"
        which seeks if an instance of this activity is already opened and
        resumes already opened instance, if not it opens new instance.
     -->
    <activity
        android:name=".presenters.register.email.GotEmailActivity"
        android:label="@string/title_activity_got_email"
        android:launchMode="singleTop" 
        android:theme="@android:style/Theme.Translucent.NoTitleBar" >

Merit of answer goes to: https://stackoverflow.com/a/34499615/5297353

like image 161
Jeka Avatar answered Oct 19 '22 23:10

Jeka


set this code in AndroidManifest.xml

android:launchMode="singleTask"

in tag activity

<activity
        android:name=".ui.live.liveinfo.LiveInfoActivity"
        android:clearTaskOnLaunch="true"
        android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden"
        android:launchMode="singleTask"
        android:parentActivityName=".ui.main.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

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

            <data
                android:host="playpod.ir"
                android:pathPrefix="/lives/live"
                android:scheme="https" />
        </intent-filter>
    </activity>
like image 45
Shaho Bashoki Avatar answered Oct 20 '22 01:10

Shaho Bashoki