public final class

ActivityLifecycleMonitorImpl

extends Object
implements ActivityLifecycleMonitor
java.lang.Object
   ↳ android.support.test.internal.runner.lifecycle.ActivityLifecycleMonitorImpl

Class Overview

The lifecycle monitor used by AndroidJUnitRunner.

Summary

Public Constructors
ActivityLifecycleMonitorImpl()
ActivityLifecycleMonitorImpl(boolean declawThreadCheck)
Public Methods
void addLifecycleCallback(ActivityLifecycleCallback callback)
Adds a new callback that will be notified when lifecycle changes occur.
Collection<Activity> getActivitiesInStage(Stage stage)
Returns all activities in a given stage of their lifecycle.
Stage getLifecycleStageOf(Activity activity)
Returns the current lifecycle stage of a given activity.
void removeLifecycleCallback(ActivityLifecycleCallback callback)
Removes a previously registered lifecycle callback.
void signalLifecycleChange(Stage stage, Activity activity)
Called by the runner after a particular onXXX lifecycle method has been called on a given activity.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.support.test.runner.lifecycle.ActivityLifecycleMonitor

Public Constructors

public ActivityLifecycleMonitorImpl ()

public ActivityLifecycleMonitorImpl (boolean declawThreadCheck)

Public Methods

public void addLifecycleCallback (ActivityLifecycleCallback callback)

Adds a new callback that will be notified when lifecycle changes occur.

Implementors will not hold a strong ref to the callback, the code which registers callbacks is responsible for this. Code which registers callbacks should responsibly remove their callback when it is no longer needed.

Callbacks are executed on the main thread of the application, and should take care not to block or otherwise perform expensive operations as it will directly impact the application.

Parameters
callback an ActivityLifecycleCallback

public Collection<Activity> getActivitiesInStage (Stage stage)

Returns all activities in a given stage of their lifecycle.

This method can only return a consistant and correct answer from the main thread, therefore callers should always invoke it from the main thread and implementors are free to throw an exception if the call is not made on the main thread.

Implementors should ensure this method returns a consistant response if called from a lifecycle callback also registered with this monitor (eg: it would be horriblely wrong if a callback sees PAUSED and calls this method with the PAUSED and does not see its activity in the response.

Callers should be aware that the monitor implementation may not hold strong references to the Activities in the application. Therefore stages which are considered end stages or eligible for garbage collection on low memory situations may not return an instance of a particular activity if it has been garbage collected.

Parameters
stage the stage to query for.
Returns
  • a snapshot Collection of activities in the given stage. This collection may be empty.

public Stage getLifecycleStageOf (Activity activity)

Returns the current lifecycle stage of a given activity.

This method can only return a consistant and correct answer from the main thread, therefore callers should always invoke it from the main thread and implementors are free to throw an exception if the call is not made on the main thread.

Implementors should ensure this method returns a consistant response if called from a lifecycle callback also registered with this monitor (eg: it would be horriblely wrong if a callback sees PAUSED and calls this method with the same activity and gets RESUMED.

Parameters
activity an activity in this application.
Returns
  • the lifecycle stage this activity is in.

public void removeLifecycleCallback (ActivityLifecycleCallback callback)

Removes a previously registered lifecycle callback.

public void signalLifecycleChange (Stage stage, Activity activity)

Called by the runner after a particular onXXX lifecycle method has been called on a given activity.