Reputation: 1690
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:
(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:
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),:
Upvotes: 5
Views: 5717
Reputation: 21
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>
Upvotes: 2
Reputation: 1690
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
Upvotes: 12