Вопрос

We are writing an android app with an intent filter as below:

        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:host="www.appname.com"
                android:scheme="http" />
            <data
                android:host="www.appname.com"
                android:scheme="https" />
        </intent-filter>

Android users with gmail who receive links to our app can choose our app as in the image below:

gmail handles our app intent-filter

However, when we look at recent apps it appears that our app is running inside the gmail process, which is not what we want. Especially if the app is already running, we'd like for gmail to hand our running process the app intent for it to load in our app. See how the gmail process has an embedded (separate instance) of the app running inside it, while the app is running in its own process:

gmail app is running a second instance of our app to complete the intent

Any advice on intent filters to resolve this would be greatly appreciated. The android documentation is not at all helpful for this type of situation.

Это было полезно?

Решение

By default, an activity belongs to the task that started it. In many cases, that's the right answer.

If, however, you want control to go to an already-running copy of your activity, from perhaps another task, add android:launchMode="singleTask" on your <activity> element in the manifest. Quoting the documentation:

The system creates a new task and instantiates the activity at the root of the new task. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance. Only one instance of the activity can exist at a time.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top