sticky
sticky

Reputation: 393

How to prevent app from creating an instance of another app during startActivityForResult?

I have app A that interacts with app B. When I launched app B using startActivityForResult, app A creates an instance of app B. While the actual app B can still be launched manually.

Is it possible to launch app B using startActivityForResult, but this time brings the actual app B to foreground?

Activity declaration on App B's Manifest:

<activity
    android:name=".activities.AppBActivity"
    android:launchMode="singleTask"
    android:screenOrientation="sensorPortrait"
    android:theme="@style/Theme.AppCompat.NoActionBar" >
    <intent-filter>
        <action android:name="intent.action.ApplicationBActivity" />
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="appBHost"
            android:scheme="appBScheme" />
    </intent-filter>
</activity>

Application A launching B.

Intent launchAppB = new Intent(appBCustomAction, Uri.parse(schemeAndHost));
startActivityForResult(launchAppB, LAUNCH_APP_B_REQUEST);

Upvotes: 1

Views: 587

Answers (1)

mr.icetea
mr.icetea

Reputation: 2637

It depends on your application B's Activity launchMode which is declared in your AndroidManifest file. You can read more about lauchMode here. In your case I suggest you to use launchMode=singleTask.

Upvotes: 2

Related Questions