Multiple Android deep link, app goes in onResume() - android

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.

Related

Receive data intent opens second app when app is opened

<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

How to start specific activity by saying OK Google?

I would like to have two activities. FirstActivity should be started from
launcher (by tapping on icon) and SecondActivity should be started by voice
command (by saying "OK Google, start play example").
The problem is that for my current configuration only FirstActivity is
started. Also method isVoiceInteraction returns false. I also don't see any values in flags that indicates that activity was started by voice.
Here's part of AndroidManifest.xml:
<application android:label="play example">
<activity android:name="com.example.FirstActivity" android:label="play example">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.EXAMPLE_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.example.SecondActivity" android:label="play example">
<intent-filter>
<action android:name="com.example.EXAMPLE_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
</activity>
</application>
Here it states:
To specify the text to say after "Start", specify a label attribute for the activtiy that you want to start.
But when I change label for SecondActivity it does not help.
I'm using API version 26.
How to setup configuration to handle described behavior?
AFAIK isVoiceInteraction will always return false when the application is opened using "open" voice command. However, the scenario which you described, having another activity to respond to voice commands, should've worked.
The only thing that you might have missed is to put the action android.intent.action.MAIN in the second activity.

Android - Reacting to assist request

I am programming a tiny app which opens the camera as it is opened via assist-request.
In the onCreate method, it simply opens the camera via intent.
But if the app is opened "the regular way" I'd like to display a little instruction instead of the camera.
Is there an easy solution for checking if the app was started by an assist-request?
extract from my Manifest:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
If you want to determine which sort of Intent was used to start MainActivity, use getIntent().getAction() and compare it to the possible values (e.g., Intent.ACTION_MAIN).

adding custom action won't start the activity when running it in the emulator

I have the following code in my Manifest:
<activity android:name="com.fletech.android.apparent.CategoriesGrid"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I run the app in Eclipse it starts this activity in the emulator, as expected.
But when I also add:
<action android:name="com.fletech.android.apparent.action.APPARENT_MAIN" />
right below the other action, and run the app, it only installs it to the emulator but doesn't run it. Why?
What I wanted to achieve is this: I would like to be able to show a dialog to the user (from another apps) to chose between all my apps that have "com.fletech.android.apparent.action.APPARENT_MAIN" as an action.
If you want to specify another launch scenario, you should just add another whole intent-filter block rather than putting all of the action clauses in the same one.

Android: proper intent-filter to indicate my application can open a filetype?

I am trying to configure my manifest file to indicate my application can open PDF files. The below configuration works, but it gives some funny behavior with the emulator:
When the "view" action is present, my application is not started on install (when I run from Eclipse, the application gets installed on the emulator, but it does not start automatically).
When application/pdf is present, after running from eclipse the application doesn't show up in my emulator's application menu.
(I don't see either of these issues if my only intents are "main" and "launcher")
<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.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
EDIT: Okay, I was a little confused about intents. The solution to my above issues is to have 2 different intent-filters, as shown below.
However, I do have a second question. Android successfully launches my app for PDF files, but when it launches onCreate(bundle) is called and not startActivity(Intent). How should I get the intent data?
<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" />
<data android:mimeType="application/pdf" />
</intent-filter>
In your Activity, you can use getIntent() to get the intent used to start it.
startIntent() is not a callback. Its a method for you to call in order to launch another intent.
When your Activity is launched, you will get your onStart() (and onCreate, just before that), called, and from there you call getIntent() to re

Categories

Resources