Intent for opening url creates new instance - android

I added an intent filter in the Android Manifest to handle intents for opening a URL:
<activity android:name=".TestActivity"
android:label="Test" android:theme="#style/Theme.Titanium"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
android:launchMode="singleTop" >
<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:scheme="http" android:host="test.com" />
</intent-filter>
</activity>
The issue I have is when the App is already open, this code launches a new instance of the App which can be very confusing to the user. After the launching the new instance, if the user navigates away using the Home Button and then returns to the App, they see the 1st instance. How can I Fix this?

android:launchMode="singleInstance" >

Related

Android deep link: Skip splash screen if app has already launched/opened

I would like when users click on a link with below format, they will be given the option to directly launch the app https://www.somedomain.com/asia/country?name=blabla. If the app hasn't launched yet, it should launch the SplashScreenActivity screen; But if the app has already opened, I would like to skip the SplashScreenActivity screen and directly show MainActivity screen.
I configured my manifest as below and set SplashScreenActivity as singleTask, but every time I tap on the deep link url, it launch from start (SplashScreenActivity). Is there any way to work around this?
<activity
android:name=".myapp.ui.SplashScreenActivity"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="#style/FullScreen">
<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="www.somedomain.com"
android:path="/asia/country"
android:scheme="https"/>
</intent-filter>
</activity>
<activity
android:name=".myapp.ui.MainActivity"
android:configChanges="layoutDirection|locale"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustNothing" >
</activity>
Add Intent Filter
<activity
android:name="Your Activity"
android:label="Your Activity Title"
android:theme="Your Style">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="your url"
android:path="/your path"
android:scheme="http" />
</intent-filter>
</activity>
If you have set the launch mode(singletask) of your SplashActvity then when you SplashActivity will open a method will be called
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
use this method to navigate to the MainActivity.

On clicking a url for deeplink my app showing 2 app instance on bottom

How to avoid multiple instances of the app for deep-link. and also email verification is not completed or its not verified even after clicking Get Started and choosing one of the these 2 below apps. how to verify the account on clicking the Get started button , immediately launching the App single instance.
Probably,you declare two activities for DeepLink Check Your manifest file you must create two Activities with Browse able , And with Same Host and Schema. Remove Browse able tag from one of them OR change Schema.
OR
Your Device (emulator) having two application with Activity having same Host and Schema. may you have tested your code for DeepLinking .
This is probably because of adding the nav graph option in more than one activity
in my case:-
<activity
android:name="com.aatec.bit.ui.activity.SplashScreen"
android:exported="true"
android:theme="#style/Theme.customSplash">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<nav-graph android:value="#navigation/nav_graph" />
</activity>
<activity
android:name="com.aatec.bit.ui.activity.main_activity.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="#style/Theme.BITApp"
android:windowSoftInputMode="adjustResize">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="bitapp-eng.github.io" />
</intent-filter>
<nav-graph android:value="#navigation/nav_graph" />
</activity>
I just remove nav_graph from my splash screen activity
<activity
android:name="com.aatec.bit.ui.activity.SplashScreen"
android:exported="true"
android:theme="#style/Theme.customSplash">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.aatec.bit.ui.activity.main_activity.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="#style/Theme.BITApp"
android:windowSoftInputMode="adjustResize">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="bitapp-eng.github.io" />
</intent-filter>
<nav-graph android:value="#navigation/nav_graph" />
</activity>

Android: after installing an APK, the open button is disabled

I read in so many places that the problem is related to the manifest and the definition of the first activity. It seems that I'm doing fine but still the open button, after installing the APK, is disabled and I don't see the icon on the device
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="www.example.com"/>
</intent-filter>
</activity>
<activity android:name=".DateSelectorActivity"
android:label="#string/app_name">
</activity>
</application>
Your problem is this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="www.example.com"/>
</intent-filter>
Here, you are saying that this activity will only be launched if:
the Intent has an action of MAIN or VIEW, and
the Intent has the categories of LAUNCHER or BROWSABLE, and
the Intent has a Uri with a scheme of http and a host of www.example.com
The home screen launcher and Settings app will not be creating such an Intent, and so they cannot launch this activity.
Either:
Remove the VIEW, BROWSABLE, and <data> portions of what you have, or
Move those into a separate <intent-filter>:
<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.BROWSABLE" />
<data android:scheme="http"
android:host="www.example.com"/>
</intent-filter>
Multiple <intent-filter> elements represent an OR operation: an Intent that matches the first filter or the second filter will work for this activity.
I ran into the same problem, but maybe caused by different reason.
Running following command line worked:
adb uninstall com.company.mayapp

How to handle same intent filter for two activities?

I am trying to implement deep linking in my app. I have two activities: SplashScreenActivity and MainActivity. Both activities have the same intent filter, such as:
<activity
android:name="com.example.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:host="product"
android:scheme="gg" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name="com.example.SplashScreenActivity" >
<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="product"
android:scheme="gg" />
</intent-filter>
</activity>
What i do is: when app is already open, i want MainActivity to be triggered and when app is not open i want splashScreenActivity to be triggered. But a popup appears and expects me to choose one of these activities, i do not want that. I want it to be automatically chosen. So, how can i implement this?
Thanks
-> First of all, you don't want to have multiple options to choose means you want only one option. So simply you should have only one Activity to handle such event.
i.e.: As mentioned below, you should have DeepLinkingActivity in manifest file.
<activity
android:name="com.example.DeepLinkingActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:host="product"
android:scheme="gg" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name="com.example.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.SplashScreenActivity" >
<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" />
</intent-filter>
</activity>
-> You want to decide the next flow based upon some condition like whether your app is in foreground or not, so simply put that logic in DeepLinkingActivity and make sure you don't setup any layout file for that activity.
i.e.:
private boolean isAppInForeground(Context ctx) {
ActivityManager activityManager = (ActivityManager) ctx.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE);
if (services == null) {
return false;
}
if (services.size() > 0 && services.get(0).topActivity.getPackageName().toString().equalsIgnoreCase(ctx.getApplicationContext().getPackageName().toString())) {
return true;
}
return false;
}
Based upon above logic, you may redirect the user to either SplashScreenActivity or MainActivity.
Note:
As you want to retrieve currently going on tasks, you will need to add below permission in your manifest file.
<uses-permission android:name="android.permission.GET_TASKS" />
You face expected behavior. If you have two activities handle same intent you will facing chooser dialog.
Remove Intent-filter from MainActivity, and add android:launchMode=singleTask:
<activity
android:name="com.gittigidiyormobil.MainActivity"
android:launchMode=singleTask>
</activity>
<activity
android:name="com.gittigidiyormobil.SplashScreenActivity" >
<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="product"
android:scheme="gg" />
</intent-filter>
</activity>
And just post you Intent through SplashScreenActivity to MainActivity and handle Intent in onNewEvent and in onCreate functions. more about launchMode
Hope it helps.
In your case you are using both Launcher and Default for a single Activity(SplashScreenActivity) that is the problem. For your need first check the application is open or not. If the application is open before setcontentview method in this SplashScreenActivity start the mainActivity. if application is not open start SplashScreenActivity. Hope this will help you :)

Open application from shared social platform

If someone shares http://myappAdurl.com from facebook than if another one clicks link, if application exist on that device, my app should be open,
I added following line to my manifest but I could not get the result, not working.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".TinyUrlTest"
android:label="#string/title_activity_tiny_url_test"
android:launchMode="singleTask" >
<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="www.myappAdurl.com"
android:path="/images"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="www.myappAdurl.com" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
I also tried below project but it opens link such as com.commonsware.android.MY_ACTION
https://github.com/commonsguy/cw-advandroid/tree/master/Introspection/URLHandler
ok found that,
if i give
android:pathPattern="/*.*"
inside data element, then it opens everything

Categories

Resources