0

I am using Branch IO in my application and as per their documentation, I am using android:launchMode="singleTask" for my activity.

Here is some code snippet of my AndroidManifest.

        <activity
        android:name=".SplashScreen"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <data
                android:host="open"
                android:scheme="com.package.name" />

            <action android:name="android.intent.action.VIEW" />

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

        <!-- Branch App Links (optional) -->
        <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="app.link"
                android:scheme="https" />
            <!-- <data android:scheme="https" android:host="example-alternate.app.link" /> -->
        </intent-filter>
    </activity>

Everything is working fine except when I press Home button while using app and tap on App/Launcher Icon, onCreate method of Splash screen activity is called which makes it looks like app is launched from beginning. However, if I press home button while using an app and open it from recent apps, onCreate is not called and everything works perfectly.

How do I make consistent app behavior when brought to foreground from recent apps and App/Launcher icon?

I tried removing singleTask launch mode which makes launch perfect from App/Launcher icon and recent apps but when tapped on branch IO link, the new instance of an app is created. I can understand that to overcome this problem only they are asking to put singleTask in launch mode.

I have checked for this scenario in many apps which are using deep links and they do not have this problem!

I must be doing something wrong which I cannot see.

Is something is missing or implementation is wrong?

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
Mihir Patel
  • 456
  • 7
  • 20

1 Answers1

0

Solution to this problem is moving to Single activity architecture. As splash activity is singleTask, onStart method of it will be called each time when the app is brought to foreground from launcher icon. One has to write routing logic in onStart method, when another activity is started from here, app state will lose. If a single activity is there, this problem will not be there. However one will have to deal with nasty fragment backstacks. Not an easy but correct approach.

For a quick workaround, one can use this code in onCreate method of activity with launchmode as singleTask.

        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
           return;
        }

This might help to avoid unnessary execution of code written in onCreate. However this is a recommended solution as it doesn't solve rootcause of problem.

Mihir Patel
  • 456
  • 7
  • 20
  • Hey @mihir-patel, this is Vatsal from Branch.io and I wanted to follow-up if the issue has been resolved. If not please let me know or feel free to write to us at integrations@branch.io – xblack Oct 31 '18 at 08:42