-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivityLifecycleCallbacks.cs
70 lines (60 loc) · 2.34 KB
/
ActivityLifecycleCallbacks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//-----------------------------------------------------------------------
// <copyright file="ActivityLifecycleCallbacks.cs" company="In The Hand Ltd">
// Copyright (c) 2023 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License
// </copyright>
//-----------------------------------------------------------------------
using Android.App;
using Android.OS;
using System;
namespace InTheHand
{
internal sealed class ActivityLifecycleCallbacks : Java.Lang.Object, Application.IActivityLifecycleCallbacks, IDisposable
{
private void SetCurrentActivityIfRequired(Activity activity)
{
if (AndroidActivity.CurrentActivity == null)
{
System.Diagnostics.Debug.WriteLine("Setting CurrentActivity");
AndroidActivity.CurrentActivity = activity;
}
}
public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
{
System.Diagnostics.Debug.WriteLine("OnActivityCreated");
SetCurrentActivityIfRequired(activity);
}
public void OnActivityDestroyed(Activity activity)
{
System.Diagnostics.Debug.WriteLine("OnActivityDestroyed");
}
public void OnActivityPaused(Activity activity)
{
System.Diagnostics.Debug.WriteLine("OnActivityPaused");
SetCurrentActivityIfRequired(activity);
}
public void OnActivityResumed(Activity activity)
{
System.Diagnostics.Debug.WriteLine("OnActivityResumed");
SetCurrentActivityIfRequired(activity);
}
public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
{
System.Diagnostics.Debug.WriteLine("OnActivitySaveInstanceState");
}
public void OnActivityStarted(Activity activity)
{
System.Diagnostics.Debug.WriteLine("OnActivityStarted");
SetCurrentActivityIfRequired(activity);
}
public void OnActivityStopped(Activity activity)
{
System.Diagnostics.Debug.WriteLine("OnActivityStopped");
}
protected override void Dispose(bool disposing)
{
((Application)Application.Context).UnregisterActivityLifecycleCallbacks(this);
base.Dispose(disposing);
}
}
}