Added in API level 1

ActivityMonitor

open class ActivityMonitor
kotlin.Any
   ↳ android.app.Instrumentation.ActivityMonitor

Information about a particular kind of Intent that is being monitored. An instance of this class is added to the current instrumentation through #addMonitor; after being added, when a new activity is being started the monitor will be checked and, if matching, its hit count updated and (optionally) the call stopped and a canned result returned.

An ActivityMonitor can also be used to look for the creation of an activity, through the waitForActivity method. This will return after a matching activity has been created with that activity object.

Summary

Public constructors

Create a new ActivityMonitor that looks for a particular kind of intent to be started.

Create a new ActivityMonitor that looks for a specific activity class to be started.

Create a new ActivityMonitor that can be used for intercepting any activity to be started.

Public methods
IntentFilter!

Retrieve the filter associated with this ActivityMonitor.

Int

Retrieve the number of times the monitor has been hit so far.

Activity!

Retrieve the most recent activity class that was seen by this monitor.

Instrumentation.ActivityResult!

Retrieve the result associated with this ActivityMonitor, or null if none.

Boolean

Check whether this monitor blocks activity starts (not allowing the actual activity to run) or allows them to execute normally.

open Instrumentation.ActivityResult!

Used for intercepting any started activity.

Activity!

Block until an Activity is created that matches this monitor, returning the resulting activity.

Activity!

Block until an Activity is created that matches this monitor, returning the resulting activity or till the timeOut period expires.

Public constructors

ActivityMonitor

Added in API level 1
ActivityMonitor(
    which: IntentFilter!,
    result: Instrumentation.ActivityResult!,
    block: Boolean)

Create a new ActivityMonitor that looks for a particular kind of intent to be started.

Parameters
which IntentFilter!: The set of intents this monitor is responsible for.
result Instrumentation.ActivityResult!: A canned result to return if the monitor is hit; can be null.
block Boolean: Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed.

See Also

    ActivityMonitor

    Added in API level 1
    ActivityMonitor(
        cls: String!,
        result: Instrumentation.ActivityResult!,
        block: Boolean)

    Create a new ActivityMonitor that looks for a specific activity class to be started.

    Parameters
    cls String!: The activity class this monitor is responsible for.
    result Instrumentation.ActivityResult!: A canned result to return if the monitor is hit; can be null.
    block Boolean: Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed.

    See Also

      ActivityMonitor

      Added in API level 1
      ActivityMonitor()

      Create a new ActivityMonitor that can be used for intercepting any activity to be started.

      When an activity is started, onStartActivity(android.content.Intent) will be called on instances created using this constructor to see if it is a hit.

      Public methods

      getFilter

      Added in API level 1
      fun getFilter(): IntentFilter!

      Retrieve the filter associated with this ActivityMonitor.

      getHits

      Added in API level 1
      fun getHits(): Int

      Retrieve the number of times the monitor has been hit so far.

      getLastActivity

      Added in API level 1
      fun getLastActivity(): Activity!

      Retrieve the most recent activity class that was seen by this monitor.

      getResult

      Added in API level 1
      fun getResult(): Instrumentation.ActivityResult!

      Retrieve the result associated with this ActivityMonitor, or null if none.

      isBlocking

      Added in API level 1
      fun isBlocking(): Boolean

      Check whether this monitor blocks activity starts (not allowing the actual activity to run) or allows them to execute normally.

      onStartActivity

      Added in API level 26
      open fun onStartActivity(intent: Intent!): Instrumentation.ActivityResult!

      Used for intercepting any started activity.

      A non-null return value here will be considered a hit for this monitor. By default this will return null and subclasses can override this to return a non-null value if the intent needs to be intercepted.

      Whenever a new activity is started, this method will be called on instances created using ActivityMonitor() to check if there is a match. In case of a match, the activity start will be blocked and the returned result will be used.

      Parameters
      intent Intent!: The intent used for starting the activity.
      Return
      Instrumentation.ActivityResult! The ActivityResult that needs to be used in case of a match.

      waitForActivity

      Added in API level 1
      fun waitForActivity(): Activity!

      Block until an Activity is created that matches this monitor, returning the resulting activity.

      Return
      Activity! Activity

      waitForActivityWithTimeout

      Added in API level 1
      fun waitForActivityWithTimeout(timeOut: Long): Activity!

      Block until an Activity is created that matches this monitor, returning the resulting activity or till the timeOut period expires. If the timeOut expires before the activity is started, return null.

      Parameters
      timeOut Long: Time to wait in milliseconds before the activity is created.
      Return
      Activity! Activity