<activity
android:name=".activitys.SplashScreen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
When app is sterted, trying to share the text and app is launching but if open pervious app by android navigation button i see 2 my app exemplars. How to check if app is launched and reopen not open second at one time
Simple answer: you need to add
android:launchMode="singleInstance"
within your activity bracket (below android:name=".activitys.SplashScreen", for example)
Better answer: Go through this article to understand the different types of launch modes: https://medium.com/#iammert/android-launchmode-visualized-8843fc833dbe
Best answer: Read through the doc on tasks: https://developer.android.com/guide/components/activities/tasks-and-back-stack
Related
I implemented an app using NFC which has URL link. So, When NFC is on, the mobile detects URL and opens my app.
I made it happen like this:
<activity
android:name=".view.main.MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="example.com"
android:scheme="http" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter" />
</activity>
However, the problem is, I have many activities and fragments. It works even while I use my application and It keeps open my application on each and every activities and fragments.
I don't want this behaviour. I want it detects URL just out of my application. How can I achieve this behaviour?
make it single task to avoid multiple opening of the activity
android:launchMode="singleTask"
also read this doc maybe help you
TL;DR Can i use two actions and two categories in one intent-filter?
My app is made up of one activity and five fragments. I have an Intent Filter in this activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Today, I saw a lint message "App is not indexable by Google..." around the application tag in manifest file. So, I did some searching and came to know that you can use this to index your app through google search. If an android user browses web link "www.example.com/myapp" from chrome/systemBrowser, he will be taken to my app instead of web page. right?
Now, I have to add an ActionView to the activity. and, my intent-filter will become,
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="www.example.com" android:pathPrefix="/myapp" />
</intent-filter>
But, I have read that using two actions is not good. It is a Logical OR operation. Intent-Filter will match only one of them:
an intent with MAIN action and LAUNCHER Category
an intent with MAIN action and BROWSABLE Category
an intent with VIEW action and LAUNCHER Category
an intent with VIEW action and BROWSABLE Category
As i understand it, It should open app on device with first option, and when a user browses the browser with provided "www.example.com/myapp", it should use first and fourth option to open the app from link.
I have looked at this question, but i need to be sure with an example.
It is confusing. I might be entirely wrong, please guide me.
By the help of someone from SO Chat, I was told to use separate intent-filters
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name">
<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" android:pathPrefix="/prefix" />
</intent-filter>
</activity>
I have an html page with two links as follow:
Test 1
Test 2
I open it with android Internet app. In my "Hello word" manifest application i declare:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="testapp">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myApp" />
</intent-filter>
</activity>
I can open my application with both links.The first time i click on both links my app starts and passes through onCreate (my app was not in background before click). The second time (app now is in recent tasks), the first link clicked before in chronologically order pass through onResume only but the second pass on onCreate. This will be the behaviour if i try open links n times until i kill application from recent. Any ideas?Thanks!
An Android activity, by default can be instantiated multiple times. You should use android:launchMode="singleTask" to override this behavior. There are some other flags that might interest you if you - here is the link to documentation.
Hoping someone can point out my failure here. Ive developed a custom launcher app which I want to replace the home screen. I also want the activity accessible via a custom URL "myapp://launcher.android.com."
I'd love to explain why, but to cut a long story short, the Android Gods demanded that I consolidate two activities (each working fine) into a single Activity.
Can someone check over my manifest file to point out any errors or fields I need to fix? Or even a superior alternative?
<activity
android:name=".KioskLauncher"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
<intent-filter>
<data android:scheme="myapp" android:host="kiosk.androiddev.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
You need an extra attribute to be added to the activity tag.
Try adding this to the activity tag:
android:launchMode="singleTask"
in my app, there is two activity and i want to make activity1 to the starting activity after installation.
But now the RUN button (is showed right after packgae installing) is disabled.
below is the manifest file. thanks.
<activity ...1>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity ...2>
<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.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</activity>
android) can i set a default activity that runs right after installing
No activity "runs right after installing". The user has to launch it from the launcher.
below is the manifest file
No, it is not. That is not even valid XML.
Also, note that your third <intent-filter> is invalid. Not only are you missing any category (you need at least DEFAULT for activities), but ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED are not activity actions.
I am going to take a guess that you really mean to ask: "I have two activities, both described as ACTION_MAIN/CATEGORY_LAUNCHER, and now the Run button does not work -- what can I do?" The answer would be "either remove the ACTION_MAIN/CATEGORY_LAUNCHER <intent-filter> from one of them, or mark one of the two as disabled (android:enabled="false") and enable it later on using PackageManager."
I think the problem is the second:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You shouldn't have 2 activities flagged as the MAIN and LAUNCHER activity.
Try removing it within activity2.
Check out: http://developer.android.com/reference/android/content/Intent.html the intentfilter s are discussed.