Platform helpers

The static Platform class, in the Microsoft.Maui.ApplicationModel namespace, contains helpers for each platform.

The Platform class contains the following helpers on Android:

Member Purpose
ActivityStateChanged An event that's raised when any Activity's state changes.
AppContext A property that gets the Context object that represents the current app context.
CurrentActivity A property that gets the current Activity object that represents the current activity.
Intent A static class that contains the ActionAppAction string, which is the identifier for the Intent used by app actions.
OnNewIntent Pass an Intent from an activity's overridden method, when invoking an app action.
OnResume Pass an Activity from an activity's overridden method, when an Activity is resumed as part of invoking an app action.
OnRequestPermissionsResult Pass permission request results from an activity's overridden method, for handling internal permission requests.
WaitForActivityAsync Wait for an Activity to be created or become active.

The following example shows how to access the current Context or Activity for the running app:

var context = Platform.AppContext;

// Current Activity or null if not initialized or not started.
var activity = Platform.CurrentActivity;

If there's a situation where the Activity is needed, but the app hasn't fully started, call the WaitForActivityAsync method:

var activity = await Platform.WaitForActivityAsync();