Compartilhar via


Activity.OnPause Method

Definition

Called as part of the activity lifecycle when the user no longer actively interacts with the activity, but it is still visible on screen.

[Android.Runtime.Register("onPause", "()V", "GetOnPauseHandler")]
protected virtual void OnPause ();
[<Android.Runtime.Register("onPause", "()V", "GetOnPauseHandler")>]
abstract member OnPause : unit -> unit
override this.OnPause : unit -> unit
Attributes

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 android.os.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 android.os.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.

<em>Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.</em>

Java documentation for android.app.Activity.onPause().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also