-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native lifecycle events #495
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6b68ae0
Implement native lifecycle events for Android and iOS
jsuarezruiz 84f4045
Merge branch 'main' into native-lifecycleevents
jsuarezruiz 44d78cc
Merge branch 'main' into native-lifecycleevents
jsuarezruiz 3578469
Fix build error
jsuarezruiz a72c979
Merge branch 'main' into native-lifecycleevents
mattleibow afd504b
Merge remote-tracking branch 'origin/main' into native-lifecycleevents
mattleibow 9d9b471
Update things to new things
mattleibow fb3bf46
Merge branch 'main' into native-lifecycleevents
jsuarezruiz a002b5e
Fix build errors
jsuarezruiz e89181f
Renamed Platform lifetime interfaces and mapped more methods
jsuarezruiz d563019
Merge branch 'main' into native-lifecycleevents
mattleibow 3ff2eeb
Bad merge
mattleibow 9f40012
Merge remote-tracking branch 'origin/main' into native-lifecycleevents
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Controls/samples/Controls.Sample/Services/Android/CustomAndroidLifecycleHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Runtime.CompilerServices; | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.Res; | ||
using Android.OS; | ||
using Microsoft.Maui; | ||
|
||
namespace Maui.Controls.Sample.Services | ||
{ | ||
public class CustomAndroidLifecycleHandler : AndroidApplicationLifetime | ||
{ | ||
public override void OnCreate(Activity activity, Bundle savedInstanceState) => LogMember(); | ||
|
||
public override void OnPostCreate(Activity activity, Bundle savedInstanceState) => LogMember(); | ||
|
||
public override void OnDestroy(Activity activity) => LogMember(); | ||
|
||
public override void OnPause(Activity activity) => LogMember(); | ||
|
||
public override void OnResume(Activity activity) => LogMember(); | ||
|
||
public override void OnPostResume(Activity activity) => LogMember(); | ||
|
||
public override void OnStart(Activity activity) => LogMember(); | ||
|
||
public override void OnStop(Activity activity) => LogMember(); | ||
|
||
public override void OnRestart(Activity activity) => LogMember(); | ||
|
||
public override void OnSaveInstanceState(Activity activity, Bundle outState) => LogMember(); | ||
|
||
public override void OnRestoreInstanceState(Activity activity, Bundle savedInstanceState) => LogMember(); | ||
|
||
public override void OnConfigurationChanged(Activity activity, Configuration newConfig) => LogMember(); | ||
|
||
public override void OnActivityResult(Activity activity, int requestCode, Result resultCode, Intent data) => LogMember(); | ||
|
||
static void LogMember([CallerMemberName] string name = "") => | ||
System.Diagnostics.Debug.WriteLine("LIFECYCLE: " + name); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Controls/samples/Controls.Sample/Services/iOS/CustomIosLifecycleHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using Foundation; | ||
using Microsoft.Maui; | ||
using UIKit; | ||
|
||
namespace Maui.Controls.Sample | ||
{ | ||
public class CustomIosLifecycleHandler : IosApplicationLifetime | ||
{ | ||
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) | ||
{ | ||
LogMember(); | ||
|
||
return true; | ||
} | ||
|
||
public override void OnActivated(UIApplication application) => LogMember(); | ||
|
||
public override void OnResignActivation(UIApplication application) => LogMember(); | ||
|
||
public override void WillTerminate(UIApplication application) => LogMember(); | ||
|
||
public override void DidEnterBackground(UIApplication application) => LogMember(); | ||
|
||
public override void WillEnterForeground(UIApplication application) => LogMember(); | ||
|
||
static void LogMember([CallerMemberName] string name = "") => | ||
Debug.WriteLine("LIFECYCLE: " + name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/Core/src/Platform/Android/AndroidApplicationLifetime.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.Res; | ||
using Android.OS; | ||
using Android.Runtime; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public class AndroidApplicationLifetime : IAndroidApplicationLifetime | ||
{ | ||
public virtual void OnCreate(Activity activity, Bundle? savedInstanceState) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnPostCreate(Activity activity, Bundle? savedInstanceState) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnDestroy(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnPause(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnResume(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnPostResume(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnStart(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnStop(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnRestart(Activity activity) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnSaveInstanceState(Activity activity, Bundle outState) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnRestoreInstanceState(Activity activity, Bundle savedInstanceState) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnConfigurationChanged(Activity activity, Configuration newConfig) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnActivityResult(Activity activity, int requestCode, [GeneratedEnum] Result resultCode, Intent? data) | ||
{ | ||
|
||
} | ||
|
||
public virtual void OnBackPressed(Activity activity) | ||
{ | ||
|
||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/Core/src/Platform/Android/IAndroidApplicationLifetime.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.Res; | ||
using Android.OS; | ||
using Android.Runtime; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
/// <summary> | ||
/// Allow to get Android Activity lifecycle callbacks. | ||
/// </summary> | ||
public interface IAndroidApplicationLifetime : IPlatformApplicationLifetime | ||
{ | ||
/// <summary> | ||
/// Called when the activity is starting. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
/// <param name="savedInstanceState">Previous state saved.</param> | ||
void OnCreate(Activity activity, Bundle? savedInstanceState); | ||
|
||
/// <summary> | ||
/// Called when activity start-up is complete (after OnStart() and OnRestoreInstanceState(Bundle) have been called). | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
/// <param name="savedInstanceState">Previous state saved.</param> | ||
void OnPostCreate(Activity activity, Bundle? savedInstanceState); | ||
|
||
/// <summary> | ||
/// Called when the activity had been stopped, but is now again being displayed to the user. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
void OnStart(Activity activity); | ||
|
||
/// <summary> | ||
/// Called for your activity to start interacting with the user. | ||
/// This is an indicator that the activity became active and ready to receive input. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
void OnResume(Activity activity); | ||
|
||
/// <summary> | ||
/// Called when activity resume is complete (after OnResume() has been called). | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
void OnPostResume(Activity activity); | ||
|
||
/// <summary> | ||
/// Called as part of the activity lifecycle when the user no longer actively interacts with the activity, | ||
/// but it is still visible on screen. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
void OnPause(Activity activity); | ||
|
||
/// <summary> | ||
/// Called when you are no longer visible to the user. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks</param> | ||
void OnStop(Activity activity); | ||
|
||
/// <summary> | ||
/// Called after OnStop when the current activity is being re-displayed to the user (the user has navigated back to it). | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks</param> | ||
void OnRestart(Activity activity); | ||
|
||
/// <summary> | ||
/// This can happen either because the activity is finishing, or because the system is | ||
/// temporarily destroying this instance of the activity to save space. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
void OnDestroy(Activity activity); | ||
|
||
/// <summary> | ||
/// Called to retrieve per-instance state from an activity before being killed so that the state can be | ||
/// restored in OnCreate or OnRestoreInstanceState. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
/// <param name="outState">Bundle in which to place your saved state.</param> | ||
void OnSaveInstanceState(Activity activity, Bundle outState); | ||
|
||
/// <summary> | ||
/// Restore the state of the dialog from a previously saved bundle. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
/// <param name="savedInstanceState">The state of the dialog previously saved.</param> | ||
void OnRestoreInstanceState(Activity activity, Bundle savedInstanceState); | ||
|
||
/// <summary> | ||
/// Called when the current configuration of the resources being used by the application have changed. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
/// <param name="newConfig">The new resource configuration.</param> | ||
void OnConfigurationChanged(Activity activity, Configuration newConfig); | ||
|
||
/// <summary> | ||
/// Called when an activity you launched exits, giving you the requestCode you started it with, | ||
/// the resultCode it returned, and any additional data from it. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
/// <param name="requestCode">The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.</param> | ||
/// <param name="resultCode">The integer result code returned by the child activity.</param> | ||
/// <param name="data">An Intent, which can return result data to the caller.</param> | ||
void OnActivityResult(Activity activity, int requestCode, [GeneratedEnum] Result resultCode, Intent? data); | ||
|
||
/// <summary> | ||
/// Called when the activity has detected the user's press of the back key. | ||
/// </summary> | ||
/// <param name="activity">The activity on which we receive lifecycle events callbacks.</param> | ||
void OnBackPressed(Activity activity); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to see if there is a fast way to handle multiple service registration and if it will conflict with the single registration we want for things like handlers.