Reputation: 131
I am trying to implement deep-linking in my app, I have added getIntent in the onResume method of my main activity And I am able to open my main activity from the link, but I am facing the following issues.
if I open the app by clicking on the app icon for the very first time, then the intent action will be Intent.ACTION_MAIN, this will be constant for all succeeding attempts, i.e when I open the app through a link, the intent.action is supposed to be Intent.ACTION_VIEW,but the action is always ACTION_MAIN.
if the app is opened through link from chrome, then i can see two instances of my app, i.e above chrome and my app itself.
<activity
android:name=".MainActivity"
android:hardwareAccelerated="false"
android:launchMode="singleTop"> // I used singleTop because i have implementd isTaskRoot in my main activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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:host="clip.myapp.tp"
android:pathPattern="/.*"
android:scheme="mhhds" />
</intent-filter>
</activity>
Below is onResume of My mainactivity.java file where I have implemented getIntent
@Override
protected void onResume() {
super.onResume();
mIntent = getIntent();
String appLinkAction = mIntent.getAction();
if(mIntent.getAction().equals(Intent.ACTION_VIEW)) {
Uri data = mIntent.getData();
String mIntentData = data.toString();
System.out.println("Intentdata:" + mIntentData);
}
}
Upvotes: 1
Views: 587
Reputation: 37404
it is because singleTop
won't create a new instance of activity and always use the existing one so
if I open the app by clicking on the app icon for the very first time, then the intent action will be Intent.ACTION_MAIN, this will be constant for all succeeding attempts, i.e when I open the app through a link, the intent.action is supposed to be Intent.ACTION_VIEW,but the action is always ACTION_MAIN.
Because of the mentioned reason, getIntent
will return the instance that was received first time instead override onNewIntent
which will return the instance of latest intent so use onNewItent
instead of onResume
if the app is opened through link from chrome, then i can see two instances of my app, i.e above chrome and my app itself
It's because that your app was previously opened as stand alone (now in stack history) and now it is opened in chrome as a search result so it's normal behaviour.
Upvotes: 2