I checked this issue reported on git, many people reported it, but there was no proper solution available there.
It all works fine, if i app is killed and no process of app exists in memory.
But my use case is to get branch link from Push Notification.
I have also set splashActivity as SingleTask
android:launchMode="singleTask"
I am getting following error message.
BRANCH_SDK: Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.
Following is my code, it checks if its there any data from branch, and pass the details to HomeActivity, HomeActivity then loads specific news item based on the id.
I don't know where to pass branch_force_new_session
this info. If i pass it from Splash Intent, it just does not work.
I am using branchSDK 5.0.1
class SplashActivity : AppCompatActivity(), , Branch.BranchReferralInitListener{
override fun onStart() {
super.onStart()
Branch.sessionBuilder(this).withCallback(this).withData(if (intent != null) intent.data else null).init()
Log.d("BRANCH_SDK_00_", "onStart")
}
override fun onInitFinished(referringParams: JSONObject?, error: BranchError?) {
if (error == null) {
if(referringParams?.has("news") ==true){
isNewsItemReceivedFromBranch = true
branchAggregatedFeedItemId = referringParams.getInt("news")
//StartHomeActivity()
}
initAppStartupProcesses()
} else {
Log.e("BRANCH_SDK", error.message)
initAppStartupProcesses()
}
}
}
Manifest
<activity
android:name=".activities.SplashActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="aaa" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch URI Scheme -->
<!-- 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:scheme="https" android:host="aaa.aa.aa" />
<data android:scheme="https" android:host="aaa.aaaa" />
</intent-filter>
</activity>
A Branchster here -
This happens when app is already in the foreground and the user tries to open the app through the deeplink.
This can be avoided by updating their oNewIntent override method as below-
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
// if activity is in foreground (or in backstack but partially visible) launching the same
// activity will skip onStart, handle this case with reInitSession
private Branch.BranchUniversalReferralInitListener branchReferralInitListener = new Branch.BranchUniversalReferralInitListener() {
@Override public void onInitFinished(@Nullable BranchUniversalObject branchUniversalObject, @Nullable LinkProperties linkProperties, @Nullable BranchError error) {
// do something with branchUniversalObject/linkProperties..
}
}
If that doesn't work you can also try to use Branch.getInstance().getLatestReferringParams()
instead of reading the params received in Branch.init
in the latest version of the SDK.
I'll keep this post updated with respect to future development of the SDK.
If this happens when app is in foreground set "branch_force_new_session"
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
this.intent = intent
intent?.putExtra("branch_force_new_session", true)
Branch.sessionBuilder(this).withCallback(branchListener).reInit()
}
The same happened to me and nothing seemed to help, then I saw that the Branch tutorial was quite confusing - you need the call Branch.getAutoInstance(this) on the Application's onCreate, not the Splash/other branch receiving activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With