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),:
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.
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.
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.
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With