From 8d9bd0bfab7971b224b4afbcf203563283ef12e3 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Mon, 7 Oct 2024 18:18:34 -0700 Subject: [PATCH] Delayed Init --- BranchSDK/Platforms/Android/BranchAndroid.cs | 53 ++++++++++++------- Timber/Platforms/Android/MainActivity.cs | 12 ++++- .../Platforms/Android/Resources/branch.json | 3 ++ 3 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 Timber/Platforms/Android/Resources/branch.json diff --git a/BranchSDK/Platforms/Android/BranchAndroid.cs b/BranchSDK/Platforms/Android/BranchAndroid.cs index dd93e10..7519972 100644 --- a/BranchSDK/Platforms/Android/BranchAndroid.cs +++ b/BranchSDK/Platforms/Android/BranchAndroid.cs @@ -129,9 +129,6 @@ public static void Init(Android.App.Application app, String branchKey, IBranchBU instance.lifeCycleHandler = new BranchAndroidLifeCycleHandler(callback); app.RegisterActivityLifecycleCallbacks(instance.lifeCycleHandler); - - // we call IniSession in BranchAndroidLifeCycleHandler.OnActivityStarted - //getInstance().InitSession(callback); } public override void InitSession(IBranchSessionInterface callback) @@ -160,30 +157,48 @@ public override void InitSession(IBranchBUOSessionInterface callback) public void ReInitSession(Intent intent, IBranchSessionInterface callback, Activity activity) { - callbacksList.Clear(); - BranchSessionListener obj = new BranchSessionListener(callback); - callbacksList.Add(obj as Object); + if (intent?.Data != null) + { + callbacksList.Clear(); + BranchSessionListener obj = new BranchSessionListener(callback); + callbacksList.Add(obj as Object); - activity.Intent = intent; + Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession Activity: " + activity); - AndroidNativeBranch.SessionBuilder(activity) - .WithCallback(obj) - .WithData(intent.Data) - .ReInit(); + intent.PutExtra("branch_force_new_session", true); + activity.Intent = intent; + + AndroidNativeBranch.SessionBuilder(activity) + .WithCallback(obj) + .WithData(intent.Data) + .ReInit(); + } + else + { + Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent); + } } public void ReInitSession(Intent intent, IBranchBUOSessionInterface callback, Activity activity) { - callbacksList.Clear(); - BranchBUOSessionListener obj = new BranchBUOSessionListener(callback); - callbacksList.Add(obj as Object); + if (intent?.Data != null) + { + callbacksList.Clear(); + BranchBUOSessionListener obj = new BranchBUOSessionListener(callback); + callbacksList.Add(obj as Object); - activity.Intent = intent; + intent.PutExtra("branch_force_new_session", true); + activity.Intent = intent; - AndroidNativeBranch.SessionBuilder(activity) - .WithCallback(obj) - .WithData(intent.Data) - .ReInit(); + AndroidNativeBranch.SessionBuilder(activity) + .WithCallback(obj) + .WithData(intent.Data) + .ReInit(); + } + else + { + Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent); + } } public override void NotifyNativeInit() diff --git a/Timber/Platforms/Android/MainActivity.cs b/Timber/Platforms/Android/MainActivity.cs index bcfe220..18611a0 100644 --- a/Timber/Platforms/Android/MainActivity.cs +++ b/Timber/Platforms/Android/MainActivity.cs @@ -31,8 +31,18 @@ public class MainActivity : MauiAppCompatActivity, IBranchSessionInterface protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); - LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnCreate still"); + LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnCreate"); BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this); + + } + + protected override void OnStart() + { + base.OnStart(); + LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnStart"); + //BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this); + Branch.GetInstance().NotifyNativeToInit(); + } protected override void OnNewIntent(Intent intent) diff --git a/Timber/Platforms/Android/Resources/branch.json b/Timber/Platforms/Android/Resources/branch.json new file mode 100644 index 0000000..850912d --- /dev/null +++ b/Timber/Platforms/Android/Resources/branch.json @@ -0,0 +1,3 @@ +{ + "deferInitForPluginRuntime": true + } \ No newline at end of file