Skip to content

Commit

Permalink
Delayed Init
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Oct 8, 2024
1 parent 56e2ebd commit 8d9bd0b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
53 changes: 34 additions & 19 deletions BranchSDK/Platforms/Android/BranchAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion Timber/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Timber/Platforms/Android/Resources/branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deferInitForPluginRuntime": true
}

0 comments on commit 8d9bd0b

Please sign in to comment.