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.
Related
<activity
android:name=".activity.SplashScreenActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="#style/Theme.TescoWelcome">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.myrealapp.android.PAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.myrealapp.android.GHS" />
<category android:name="android.intent.category.DEFAULT" />
</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.myreal.com"
android:pathPrefix="/clubcard"
android:scheme="https" />
</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="*"
android:scheme="real-myapp" />
</intent-filter>
</activity>
<activity
android:name=".features.welcome.view.WelcomeActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.MYREALAPP" />
This is my activity I am trying to update the app from google play from the current version to a new version which is in play store what happened in that case when we kill the app and try to update the app in that case launcher activity call but when we go in welcome activity and minimize app then go in google play try to update the app in that case what happened Launcher activity on creating not calling it to call welcome activity which is next of splash activity. please I don't know why this behavior in the android app ideally it should call launcher activity which is Splashscreen. please help me in this issue what I am doing wrong?
I created a launcher app that contains two activities, MainActivity and DrawerActivity.
I start the other app (Music App) from DrawerActivity.
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.music");
startActivity(intent);
When I closed the music app.
I have a question. The launcher shows the page MainActivity first (very fast), then page DrawerActivity, but doesn't call onCreate or onResume (MainActivity).
Launcher AndroidManiestfest.xml
<activity
android:name=".main.MainActivity"
android:clearTaskOnLaunch="true"
android:configChanges="keyboard|keyboardHidden|navigation"
android:excludeFromRecents="true">
<intent-filter android:priority="1">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".drawer.DrawerActivity"
android:autoRemoveFromRecents="true"
android:excludeFromRecents="true"
android:screenOrientation="landscape"/>
I think it has something to do with your code line:
<intent-filter android:priority="1">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Correct me if I'm wrong, but you're prioritizing reading the intent from the first Activity with this line.
Try removing it and see if it still occurs?
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
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 :)
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" >