Class MauiActivityEvent
- Namespace
- VpnHood.AppUi.Hosting.Maui
- Assembly
- VpnHood.AppUi.Hosting.Maui.dll
Represents a MAUI activity that raises the app's activity events, for a MAUI UI on Android.
public class MauiActivityEvent : MauiAppCompatActivity, IComponentCallbacks2, IComponentCallbacks, KeyEvent.ICallback, LayoutInflater.IFactory2, LayoutInflater.IFactory, View.IOnCreateContextMenuListener, Window.ICallback, KeyEventDispatcher.IComponent, IFullyDrawnReporterOwner, IOnBackPressedDispatcherOwner, IContextAware, IActivityResultCaller, IActivityResultRegistryOwner, IOnMultiWindowModeChangedProvider, IOnNewIntentProvider, IPictureInPictureProvider, IOnPictureInPictureModeChangedProvider, IOnPictureInPictureUiStateChangedProvider, IOnUserLeaveHintProvider, IOnConfigurationChangedProvider, IOnTrimMemoryProvider, IMenuHost, IHasDefaultViewModelProviderFactory, IViewModelStoreOwner, INavigationEventDispatcherOwner, ISavedStateRegistryOwner, ILifecycleOwner, ActivityCompat.IOnRequestPermissionsResultCallback, ActivityCompat.IRequestPermissionsRequestCodeValidator, ActionBarDrawerToggle.IDelegateProvider, IAppCompatCallback, TaskStackBuilder.ISupportParentable, IJavaObject, IJavaPeerable, IDisposable, IActivityEvent
- Inheritance
-
MauiActivityEvent
- Implements
- Derived
- Inherited Members
Properties
Activity
Gets the activity.
public Activity Activity { get; }
Property Value
Methods
OnActivityResult(int, Result, Intent?)
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.
protected override void OnActivityResult(int requestCode, Result resultCode, Intent? data)
Parameters
requestCodeintThe integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.
resultCodeResultThe integer result code returned by the child activity through its setResult().
dataIntentAn Intent, which can return result data to the caller (various data can be attached to Intent "extras").
Remarks
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. The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation. An activity can never receive a result in the resumed state. You can count on onResume() being called after this method, though not necessarily immediately after. If the activity was resumed, it will be paused and the result will be delivered, followed by onResume(). If the activity wasn't in the resumed state, then the result will be delivered, with onResume() called sometime later when the activity becomes active again. This method is never invoked if your activity sets noHistory to true.
See also:
Portions of this page are modifications based on work created and shared by the
OnConfigurationChanged(Configuration)
Called by the system when the device configuration changes while your activity is running.
public override void OnConfigurationChanged(Configuration newConfig)
Parameters
newConfigConfigurationThe new device configuration.
Remarks
Called by the system when the device configuration changes while your activity is running. Note that this will only be called if you have selected configurations you would like to handle with the R.attr.configChanges attribute in your manifest. If any configuration change occurs that is not selected to be reported by that attribute, then instead of reporting it the system will stop and restart the activity (to have it launched with the new configuration). The only exception is if a size-based configuration is not large enough to be considered significant, in which case the system will not recreate the activity and will instead call this method. For details on this see the documentation on size-based config change. At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.
Portions of this page are modifications based on work created and shared by the
OnCreate(Bundle?)
Called when the activity is starting.
protected override void OnCreate(Bundle? savedInstanceState)
Parameters
savedInstanceStateBundleIf the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in
#onSaveInstanceState. <b>Note: Otherwise it is null.</b>
Remarks
Called when the activity is starting. This is where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById(int) to programmatically interact with widgets in the UI, calling managedQuery(android.net.Uri,String[],String,String[],String) to retrieve cursors for data being displayed, etc. You can call finish() from within this function, in which case onDestroy() will be immediately called after onCreate(Bundle) without any of the rest of the activity lifecycle (onStart(), onResume(), onPause(), etc.) executing. Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
See also:
Portions of this page are modifications based on work created and shared by the
OnDestroy()
Perform any final cleanup before an activity is destroyed.
protected override void OnDestroy()
Remarks
Perform any final cleanup before an activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it), or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method. Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here. This method is usually implemented to free resources like threads that are associated with an activity, so that a destroyed activity does not leave such things around while the rest of its application is still running. There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away. Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
See also:
Portions of this page are modifications based on work created and shared by the
OnKeyDown(Keycode, KeyEvent?)
Called when a key was pressed down and not handled by any of the views inside of the activity.
public override bool OnKeyDown(Keycode keyCode, KeyEvent? e)
Parameters
Returns
- bool
Return
trueto prevent this event from being propagated further, orfalseto indicate that you have not handled this event and it should continue to be propagated.
Remarks
Called when a key was pressed down and not handled by any of the views inside of the activity. So, for example, key presses while the cursor is inside a TextView will not trigger the event (unless it is a navigation to another object) because TextView handles its own key presses. If the focused view didn't want this event, this method is called. The default implementation takes care of KeyEvent.KEYCODE_BACK by calling onBackPressed(), though the behavior varies based on the application compatibility mode: for Build.VERSION_CODES.ECLAIR or later applications, it will set up the dispatch to call onKeyUp(int, KeyEvent) where the action will be performed; for earlier applications, it will perform the action immediately in on-down, as those versions of the platform behaved. This implementation will also take care of KeyEvent.KEYCODE_ESCAPE by finishing the activity if it would be closed by touching outside of it. Other additional default key handling may be performed if configured with setDefaultKeyMode(int).
See also:
Portions of this page are modifications based on work created and shared by the
OnNewIntent(Intent?)
This is called for activities that set launchMode to "singleTop" in
their package, or if a client used the Intent#FLAG_ACTIVITY_SINGLE_TOP
flag when calling #startActivity.
protected override void OnNewIntent(Intent? intent)
Parameters
intentIntentThe new intent that was used to start the activity
Remarks
This is called for activities that set launchMode to "singleTop" in their package, or if a client used the Intent.FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it. An activity can never receive a new intent in the resumed state. You can count on onResume() being called after this method, though not necessarily immediately after the completion of this callback. If the activity was resumed, it will be paused and new intent will be delivered, followed by onResume(). If the activity wasn't in the resumed state, then new intent can be delivered immediately, with onResume() called sometime later when activity becomes active again. Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.
See also:
Portions of this page are modifications based on work created and shared by the
OnPause()
Called as part of the activity lifecycle when the user no longer actively interacts with the activity, but it is still visible on screen.
protected override void OnPause()
Remarks
Called as part of the activity lifecycle when the user no longer actively interacts with the activity, but it is still visible on screen. The counterpart to onResume(). When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A's onPause() returns, so be sure to not do anything lengthy here. This callback is mostly used for saving any persistent state the activity is editing, to present a "edit in place" model to the user and making sure nothing is lost if there are not enough resources to start the new activity without first killing this one. This is also a good place to stop things that consume a noticeable amount of CPU in order to make the switch to the next activity as fast as possible. On platform versions prior to Build.VERSION_CODES.Q this is also a good place to try to close exclusive-access devices or to release access to singleton resources. Starting with Build.VERSION_CODES.Q there can be multiple resumed activities in the system at the same time, so onTopResumedActivityChanged(boolean) should be used for that purpose instead. If an activity is launched on top, after receiving this call you will usually receive a following call to onStop() (after the next activity has been resumed and displayed above). However in some cases there will be a direct call back to onResume() without going through the stopped state. An activity can also rest in paused state in some cases when in multi-window mode, still visible to user. Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
See also:
Portions of this page are modifications based on work created and shared by the
OnRequestPermissionsResult(int, string[], Permission[])
Callback for the result from requesting permissions.
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
Parameters
requestCodeintThe request code passed in
#requestPermissions.permissionsstring[]The requested permissions. Never null.
grantResultsPermission[]The grant results for the corresponding permissions which is either
android.content.pm.PackageManager#PERMISSION_GRANTEDorandroid.content.pm.PackageManager#PERMISSION_DENIED. Never null.
Remarks
Callback for the result from requesting permissions. This method is invoked for every call on requestPermissions(String, int) Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.
See also:
Portions of this page are modifications based on work created and shared by the
OnResume()
Called after #onRestoreInstanceState, #onRestart, or #onPause.
protected override void OnResume()
Remarks
Called after onRestoreInstanceState(Bundle), onRestart(), or onPause(). This is usually a hint for your activity to start interacting with the user, which is a good indicator that the activity became active and ready to receive input. This sometimes could also be a transit state toward another resting state. For instance, an activity may be relaunched to onPause() due to configuration changes and the activity was visible, but wasn't the top-most activity of an activity task. onResume() is guaranteed to be called before onPause() in this case which honors the activity lifecycle policy and the activity eventually rests in onPause(). On platform versions prior to Build.VERSION_CODES.Q this is also a good place to try to open exclusive-access devices or to get access to singleton resources. Starting with Build.VERSION_CODES.Q there can be multiple resumed activities in the system simultaneously, so onTopResumedActivityChanged(boolean) should be used for that purpose instead. Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
See also:
Portions of this page are modifications based on work created and shared by the
Events
ActivityResultEvent
Occurs when an activity this one started returns its result.
public event EventHandler<ActivityResultEventArgs>? ActivityResultEvent
Event Type
ConfigurationChangedEvent
Occurs when the device's configuration has changed, with the new one.
public event EventHandler<Configuration>? ConfigurationChangedEvent
Event Type
CreateEvent
Occurs when the activity is created.
public event EventHandler<CreateEventArgs>? CreateEvent
Event Type
DestroyEvent
Occurs when the activity is about to be destroyed.
public event EventHandler? DestroyEvent
Event Type
KeyDownEvent
Occurs when a key is pressed, before the activity handles it.
public event EventHandler<KeyDownArgs>? KeyDownEvent
Event Type
NewIntentEvent
Occurs when the activity, already running, is started again with a new intent.
public event EventHandler<NewIntentEventArgs>? NewIntentEvent
Event Type
PauseEvent
Occurs when the activity is paused.
public event EventHandler? PauseEvent
Event Type
RequestPermissionsResultEvent
Occurs when the person has answered a request for permissions.
public event EventHandler<RequestPermissionsResultArgs>? RequestPermissionsResultEvent
Event Type
Remarks
It occurs on a canceled request too, with empty results.
ResumeEvent
Occurs when the activity is resumed.
public event EventHandler? ResumeEvent