Skip to end of metadata
Go to start of metadata

Represents an Android.App.Activity class that supports ViewModel navigation.

Definition

public abstract class Activity<TViewModel> : Activity,

IActivity, IServiceAccessor, ILocationListener, ISupportLocationResult

where TViewModel : IViewModel, class

Type Parameters

TViewModel Instance of IViewModel

Summary

The following table summarizes the members exposed in this class.

Protected Constructors

Activity<TViewModel> Constructor() Initializes a new instance of the Activity<TViewModel> class.
Activity<TViewModel> Constructor(int) Initializes a new instance of the Activity<TViewModel> class.
Activity<TViewModel> Constructor(TViewModel) Initializes a new instance of the Activity<TViewModel> class.
Activity<TViewModel> Constructor(IntPtr, JniHandleOwnership) Initializes a new instance of the Activity<TViewModel> class.

Public Properties

Id Gets the activity identifier which will be retained during device rotation.
LocationCallback Gets the result location callback.
LocationManager Gets the location manager.
ViewModel Gets the related view model.

Protected Properties

ContentLayoutId Gets the content layout identifier to be inflated.
IsDisposed Gets the value indicating whether the current activity has been disposed.
IsRotated Gets the value indicating whether the current activity has been rotated.
IsRotating Gets the value indicating whether the current activity is being rotated.
MenuLayoutId Gets the menu layout identifier to be inflated.
ShowActionBarUpButton Gets a value indicating whether action bar is clickable as back navigation.
ViewModel Gets the related view model.

Public Methods

AddBinding(View, BindableProperty, BindingDescription) Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.
AddBinding(View, BindableProperty, string) Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.
AddBinding(View, BindableProperty, string, BindingMode) Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.
AddBinding(string, BindableProperty, BindingDescription) Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.
AddBinding(string, BindableProperty, string) Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.
AddBinding(string, BindableProperty, string, BindingMode) Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.
FindName(string) Finds the view with the specified string name.
FindName<T>(string) Finds the view with the specified string name.
GetService<TService>() Gets the service.
GetService<TService>(bool) Gets the service.
OnBackPressed() Called when the activity has detected the user's press of the back key.
OnCreateOptionsMenu(IMenu) Initialize the contents of the Activity's standard options menu.
OnLocationChanged(Location) Called when the location has changed.
OnOptionsItemSelected(IMenuItem) Called whenever an item in the options menu is selected.
OnProviderDisabled(string) Called when the provider is disabled by the user.
OnProviderEnabled(string) Called when the provider is enabled by the user.
OnRestoreNonConfigurationInstance() Restore non configuration instance that was previously returned by Activity<TViewModel>.
OnRetainNonConfigurationInstance() Retain non configuration instance to be used when the instance is re-created after being destroyed.
OnStatusChanged(string, Availability, Bundle) Called when the provider status changes.
RegisterViewIdentifier(string, object) Registers view identifier at runtime.
ReinitializeBinding(string, BindableProperty) Reinitializes binding after orientation changes.
RequestLocationUpdates(string, long, float, Action<LocationRequest, List<object>>) Monitors device location. Triggers on location change.
StartModalActivity(Intent, int, Action<object>) Starts the modal activity.

Protected Methods

CreateViewModel() Creates a view model based on the given IViewModel.
CreateViewState() Create the view state to store non-configuration instance which should be retained before the view is being destroyed.
Dispose(bool) Performs tasks associated with freeing, releasing, or resetting unmanaged resources.
InitializeBindings() Initializes the bindings after it has been registered.
InitializeView() Initializes the view-related logic before it is rendered.
InitializeViewModel() Initializes the view model instance.
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.
OnCreate(Bundle) Called when the activity is starting.
OnDestroy() Perform any final cleanup before an activity is destroyed.
OnNewIntent(Intent) This is called for activities that set launchMode to "singleTop" in their package, or if a client used the flag when calling .
OnPause() Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed.
OnRestart() Called after Activity<TViewModel> when the current activity is being re-displayed to the user (the user has navigated back to it).
OnRestoreInstanceState(Bundle) Called after Activity<TViewModel> when the activity is being re-initialized from a previously saved state, given here in savedInstanceState.
OnResume() Called after Activity<TViewModel>, Activity<TViewModel>, or Activity<TViewModel>, for your activity to start interacting with the user.
OnRotate() Called when the activity had been rotated and is now being displayed to the user.
OnSaveInstanceState(Bundle) Called to retrieve per-instance state from an activity before being killed.
OnStart() Called after Activity<TViewModel> or after Activity<TViewModel> when the activity had been stopped, but is now again being displayed to the user.
OnStop() Called when activity is no longer visible to the user.
OnViewCreated() Called when view is created.
OnViewDisposed() Called when the view is disposed.
OnViewInitialized() Called when view is initialized.
OnViewModelDisposed() Dispose the view model.
OnViewModelPropertyChanged(PropertyChangedEventArgs) Called when the properties of the associated view model has changed.
OnViewModelResourcesChanged() Called when the resources in view model has changed.
OnViewNavigated() Called when the view is navigated.

Events

ViewDismissed Occurs when view is dismissed.

Protected Constructors

protected Activity()

Initializes a new instance of the Activity<TViewModel> class.

protected Activity(int contentLayoutId)

Initializes a new instance of the Activity<TViewModel> class.

Parameters

contentLayoutId The content layout identifier.

protected Activity(TViewModel viewModel)

Initializes a new instance of the Activity<TViewModel> class.

Parameters

viewModel Instance of IViewModel

protected Activity(IntPtr intPtr, JniHandleOwnership handleOwnership)

Initializes a new instance of the Activity<TViewModel> class.

Parameters

intPtr The IntPtr.
handleOwnership The handle ownership.

Public Properties

public string Id { get; }

Gets the activity identifier which will be retained during device rotation.

public Action<LocationRequest, List<object>> LocationCallback { get; set; }

Gets the result location callback.

public LocationManager LocationManager { get; }

Gets the location manager.

public TViewModel ViewModel { get; }

Gets the related view model.

Protected Properties

protected int ContentLayoutId { get; }

Gets the content layout identifier to be inflated.

protected bool IsDisposed { get; }

Gets the value indicating whether the current activity has been disposed.

protected bool IsRotated { get; }

Gets the value indicating whether the current activity has been rotated.

protected bool IsRotating { get; }

Gets the value indicating whether the current activity is being rotated.

protected int MenuLayoutId { get; }

Gets the menu layout identifier to be inflated.

protected bool ShowActionBarUpButton { get; }

Gets a value indicating whether action bar is clickable as back navigation.

protected TViewModel ViewModel { set; }

Gets the related view model.

Public Methods

public void AddBinding(View targetView, BindableProperty property, BindingDescription binding)

Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.

Parameters

targetView The target Android.Views.View
property The BindableProperty
binding The BindingDescription

public void AddBinding(View targetView, BindableProperty property, string path)

Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.

Parameters

targetView The target Android.Views.View
property The BindableProperty
path The property name path

public void AddBinding(View targetView, BindableProperty property, string path, BindingMode mode)

Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.

Parameters

targetView The target Android.Views.View
property The BindableProperty
path The property name path
mode The BindingMode to be used

public void AddBinding(string targetViewName, BindableProperty property, BindingDescription binding)

Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.

Parameters

targetViewName The target Android.Views.View
property The BindableProperty
binding The BindingDescription to be used

public void AddBinding(string targetViewName, BindableProperty property, string path)

Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.

Parameters

targetViewName The string name of the target Android.Views.View
property The BindableProperty
path The property name path

public void AddBinding(string targetViewName, BindableProperty property, string path, BindingMode mode)

Adds a new BindingContext to a list of BindingContext used by Activity<TViewModel>.

Parameters

targetViewName The string name of the target Android.Views.View
property The BindableProperty
path The property name path
mode The BindingMode to be used

public object FindName(string name)

Finds the view with the specified string name.

Parameters

name The name.

Return Types

object associated with the identifier.

public T FindName<T>(string name)

Finds the view with the specified string name.

Type Parameters

T System.Type of the view

Parameters

name The name.

public TService GetService<TService>()

Gets the service.

Type Parameters

TService The type of the service.

public TService GetService<TService>(bool newInstance)

Gets the service.

Type Parameters

TService The type of the service.

Parameters

newInstance if set to true [new instance].

public void OnBackPressed()

Called when the activity has detected the user's press of the back key.

Remarks

Called when the activity has detected the user&#39;s press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/app/Activity.html#onBackPressed()&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

public bool OnCreateOptionsMenu(IMenu menu)

Initialize the contents of the Activity's standard options menu.

Remarks

Initialize the contents of the Activity&#39;s standard options menu. You should place your menu items in to &lt;format type=&quot;text/html&quot;&gt; &lt;var&gt;menu&lt;/var&gt; &lt;/format&gt; . This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see . The default implementation populates the menu with standard system menu items. These are placed in the group so that they will be correctly ordered with application-defined menu items. Deriving classes should always call through to the base implementation. You can safely hold on to &lt;format type=&quot;text/html&quot;&gt; &lt;var&gt;menu&lt;/var&gt; &lt;/format&gt; (and any items created from it), making modifications to it as desired, until the next time onCreateOptionsMenu() is called. When you add items to the menu, you can implement the Activity&#39;s method to handle them there. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

menu The options menu in which you place your items.

Return Types

To be added.

public void OnLocationChanged(Location location)

Called when the location has changed.

Remarks

Called when the location has changed. There are no restrictions on the use of the supplied Location object. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/location/LocationListener.html#onLocationChanged(android.location.Location)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

location The new location, as a Location object.

public bool OnOptionsItemSelected(IMenuItem item)

Called whenever an item in the options menu is selected.

Parameters

item The menu item that is selected.

public void OnProviderDisabled(string provider)

Called when the provider is disabled by the user.

Remarks

Called when the provider is disabled by the user. If requestLocationUpdates is called on an already disabled provider, this method is called immediately. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/location/LocationListener.html#onProviderDisabled(java.lang.String)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

provider the name of the location provider associated with this update.

public void OnProviderEnabled(string provider)

Called when the provider is enabled by the user.

Remarks

Called when the provider is enabled by the user. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/location/LocationListener.html#onProviderEnabled(java.lang.String)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

provider the name of the location provider associated with this update.

public void OnRestoreNonConfigurationInstance()

Restore non configuration instance that was previously returned by Activity<TViewModel>.

public Object OnRetainNonConfigurationInstance()

Retain non configuration instance to be used when the instance is re-created after being destroyed.

public void OnStatusChanged(string provider, Availability status, Bundle extras)

Called when the provider status changes.

Remarks

Called when the provider status changes. This method is called when a provider is unable to fetch a location or if the provider has recently become available after a period of unavailability. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/location/LocationListener.html#onStatusChanged(java.lang.String, int, android.os.Bundle)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

provider the name of the location provider associated with this update.
status if the provider is out of service, and this is not expected to change in the near future; if the provider is temporarily unavailable but is expected to be available shortly; and if the provider is currently available.
extras an optional Bundle which will contain provider specific status variables. A number of common key/value pairs for the extras Bundle are listed below. Providers that use any of the keys on this list must provide the corresponding value as described below. satellites - the number of satellites used to derive the fix

public void RegisterViewIdentifier(string id, object view)

Registers view identifier at runtime.

Parameters

id The string ID to be registered
view The Android.Views.View object to be registered

public void ReinitializeBinding(string targetViewName, BindableProperty property)

Reinitializes binding after orientation changes.

Parameters

targetViewName The target Android.Views.View name
property The BindableProperty

public void RequestLocationUpdates(string provider, long minTime, float minDistance, Action<LocationRequest, List<object>> locationCallback)

Monitors device location. Triggers on location change.

Parameters

provider The Android.Locations.LocationProvider
minTime Minimum time in milliseconds before Android.Locations.ILocationListener.OnLocationChanged(Android.Locations.Location) is triggered
minDistance Minimum distance in meters before Android.Locations.ILocationListener.OnLocationChanged(Android.Locations.Location) is triggered
locationCallback The System.Action callback

public void StartModalActivity(Intent intent, int requestCode, Action<object> callback)

Starts the modal activity.

Parameters

intent The Android.Content.Intent.
requestCode The request code.
callback The callback.

Protected Methods

protected TViewModel CreateViewModel()

Creates a view model based on the given IViewModel.

Return Types

Instance of IViewModel

protected ViewState CreateViewState()

Create the view state to store non-configuration instance which should be retained before the view is being destroyed.

Return Types

The view state which contains non-configuration instance.

protected void Dispose(bool disposing)

Performs tasks associated with freeing, releasing, or resetting unmanaged resources.

Parameters

disposing If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.

protected void InitializeBindings()

Initializes the bindings after it has been registered.

protected void InitializeView()

Initializes the view-related logic before it is rendered.

protected void InitializeViewModel()

Initializes the view model instance.

protected void OnActivityResult(int requestCode, Result resultCode, Intent data)

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.

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 &lt;format type=&quot;text/html&quot;&gt; &lt;var&gt;resultCode&lt;/var&gt; &lt;/format&gt; will be if the activity explicitly returned that, didn&#39;t return any result, or crashed during its operation. You will receive this call immediately before onResume() when your activity is re-starting. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.
resultCode The integer result code returned by the child activity through its setResult().
data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").

protected void OnCreate(Bundle savedInstanceState)

Called when the activity is starting.

Parameters

savedInstanceState If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in Activity<TViewModel>; Otherwise it is null.

protected void OnDestroy()

Perform any final cleanup before an activity is destroyed.

protected void OnNewIntent(Intent intent)

This is called for activities that set launchMode to "singleTop" in their package, or if a client used the flag when calling .

Remarks

This is called for activities that set launchMode to &quot;singleTop&quot; in their package, or if a client used the flag when calling . 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 will always be paused before receiving a new intent, so you can count on being called after this method. Note that still returns the original Intent. You can use to update it to this new Intent. &lt;format type=&quot;text/html&quot;&gt; &lt;a href=&quot;http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)&quot; target=&quot;_blank&quot;&gt; [Android Documentation] &lt;/a&gt; &lt;/format&gt;

Parameters

intent The new intent that was started for the activity.

protected void OnPause()

Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed.

protected void OnRestart()

Called after Activity<TViewModel> when the current activity is being re-displayed to the user (the user has navigated back to it).

protected void OnRestoreInstanceState(Bundle savedInstanceState)

Called after Activity<TViewModel> when the activity is being re-initialized from a previously saved state, given here in savedInstanceState.

Parameters

savedInstanceState The data most recently supplied in Activity<TViewModel>.

protected void OnResume()

Called after Activity<TViewModel>, Activity<TViewModel>, or Activity<TViewModel>, for your activity to start interacting with the user.

protected void OnRotate()

Called when the activity had been rotated and is now being displayed to the user.

protected void OnSaveInstanceState(Bundle outState)

Called to retrieve per-instance state from an activity before being killed.

Parameters

outState Bundle in which to place your saved state.

protected void OnStart()

Called after Activity<TViewModel> or after Activity<TViewModel> when the activity had been stopped, but is now again being displayed to the user.

protected void OnStop()

Called when activity is no longer visible to the user.

protected void OnViewCreated()

Called when view is created.

protected void OnViewDisposed()

Called when the view is disposed.

protected void OnViewInitialized()

Called when view is initialized.

protected void OnViewModelDisposed()

Dispose the view model.

protected void OnViewModelPropertyChanged(PropertyChangedEventArgs e)

Called when the properties of the associated view model has changed.

Parameters

e The System.ComponentModel.PropertyChangedEventArgs instance containing the event data.

protected void OnViewModelResourcesChanged()

Called when the resources in view model has changed.

protected void OnViewNavigated()

Called when the view is navigated.

Events

public event EventHandler<DismissViewEventArgs> ViewDismissed

Occurs when view is dismissed.

  • No labels