MonitoringInstrumentation
public class MonitoringInstrumentation
extends Instrumentation
java.lang.Object |
↳ |
android.app.Instrumentation |
|
↳ |
android.support.test.runner.MonitoringInstrumentation |
Known Direct Subclasses
|
一种仪器,可启用多个高级功能,并在仪器使用情况下对应用程序状态做出一些硬性保证。
A short list of these capabilities:
- Forces Application.onCreate() to happen before Instrumentation.onStart() runs (ensuring your code always runs in a sane state).
- Logs application death due to exceptions.
- Allows tracking of activity lifecycle states.
- Registers instrumentation arguments in an easy to access place.
- Ensures your activities are creating themselves in reasonable amounts of time.
- Provides facilities to dump current app threads to test outputs.
- Ensures all activities finish before instrumentation exits.
This Instrumentation is *NOT* a test instrumentation (some of its subclasses are). It makes no assumptions about what the subclass wants to do.
Summary
Inherited constants |
From class android.app.Instrumentation
String |
REPORT_KEY_IDENTIFIER |
String |
REPORT_KEY_STREAMRESULT |
|
Public methods |
void |
callActivityOnCreate(Activity activity, Bundle bundle) |
void |
callActivityOnDestroy(Activity activity) |
void |
callActivityOnPause(Activity activity) |
void |
callActivityOnRestart(Activity activity) |
void |
callActivityOnResume(Activity activity) |
void |
callActivityOnStart(Activity activity) |
void |
callActivityOnStop(Activity activity) |
void |
callApplicationOnCreate(Application app) |
void |
execStartActivities(Context who, IBinder contextThread, IBinder token, Activity target, Intent[] intents, Bundle options) |
Instrumentation.ActivityResult |
execStartActivity(Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) |
Instrumentation.ActivityResult |
execStartActivity(Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode) |
Instrumentation.ActivityResult |
execStartActivity(Context who, IBinder contextThread, IBinder token, Fragment target, Intent intent, int requestCode, Bundle options) |
void |
finish(int resultCode, Bundle results) 确保仪器退出前完成在此仪器中启动的所有活动。 |
Activity |
newActivity(Class<?> clazz, Context context, IBinder token, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, Object lastNonConfigurationInstance) |
void |
onCreate(Bundle arguments) 设置生命周期监控和参数注册表。 |
void |
onDestroy() |
boolean |
onException(Object obj, Throwable e) |
void |
onStart() onStart()的这个实现将保证应用程序的onCreate方法在返回时完成。 |
Activity |
startActivitySync(Intent intent) |
Inherited methods |
From class android.app.Instrumentation
Instrumentation.ActivityMonitor |
addMonitor(String arg0, Instrumentation.ActivityResult arg1, boolean arg2) |
Instrumentation.ActivityMonitor |
addMonitor(IntentFilter arg0, Instrumentation.ActivityResult arg1, boolean arg2) |
void |
addMonitor(Instrumentation.ActivityMonitor arg0) |
void |
callActivityOnCreate(Activity arg0, Bundle arg1) |
void |
callActivityOnCreate(Activity arg0, Bundle arg1, PersistableBundle arg2) |
void |
callActivityOnDestroy(Activity arg0) |
void |
callActivityOnNewIntent(Activity arg0, Intent arg1) |
void |
callActivityOnPause(Activity arg0) |
void |
callActivityOnPostCreate(Activity arg0, Bundle arg1, PersistableBundle arg2) |
void |
callActivityOnPostCreate(Activity arg0, Bundle arg1) |
void |
callActivityOnRestart(Activity arg0) |
void |
callActivityOnRestoreInstanceState(Activity arg0, Bundle arg1) |
void |
callActivityOnRestoreInstanceState(Activity arg0, Bundle arg1, PersistableBundle arg2) |
void |
callActivityOnResume(Activity arg0) |
void |
callActivityOnSaveInstanceState(Activity arg0, Bundle arg1, PersistableBundle arg2) |
void |
callActivityOnSaveInstanceState(Activity arg0, Bundle arg1) |
void |
callActivityOnStart(Activity arg0) |
void |
callActivityOnStop(Activity arg0) |
void |
callActivityOnUserLeaving(Activity arg0) |
void |
callApplicationOnCreate(Application arg0) |
boolean |
checkMonitorHit(Instrumentation.ActivityMonitor arg0, int arg1) |
void |
endPerformanceSnapshot() |
void |
finish(int arg0, Bundle arg1) |
Bundle |
getAllocCounts() |
Bundle |
getBinderCounts() |
ComponentName |
getComponentName() |
Context |
getContext() |
Context |
getTargetContext() |
UiAutomation |
getUiAutomation() |
boolean |
invokeContextMenuAction(Activity arg0, int arg1, int arg2) |
boolean |
invokeMenuActionSync(Activity arg0, int arg1, int arg2) |
boolean |
isProfiling() |
Activity |
newActivity(Class<?> arg0, Context arg1, IBinder arg2, Application arg3, Intent arg4, ActivityInfo arg5, CharSequence arg6, Activity arg7, String arg8, Object arg9) |
Activity |
newActivity(ClassLoader arg0, String arg1, Intent arg2) |
Application |
newApplication(ClassLoader arg0, String arg1, Context arg2) |
static Application |
newApplication(Class<?> arg0, Context arg1) |
void |
onCreate(Bundle arg0) |
void |
onDestroy() |
boolean |
onException(Object arg0, Throwable arg1) |
void |
onStart() |
void |
removeMonitor(Instrumentation.ActivityMonitor arg0) |
void |
runOnMainSync(Runnable arg0) |
void |
sendCharacterSync(int arg0) |
void |
sendKeyDownUpSync(int arg0) |
void |
sendKeySync(KeyEvent arg0) |
void |
sendPointerSync(MotionEvent arg0) |
void |
sendStatus(int arg0, Bundle arg1) |
void |
sendStringSync(String arg0) |
void |
sendTrackballEventSync(MotionEvent arg0) |
void |
setAutomaticPerformanceSnapshots() |
void |
setInTouchMode(boolean arg0) |
void |
start() |
Activity |
startActivitySync(Intent arg0) |
void |
startAllocCounting() |
void |
startPerformanceSnapshot() |
void |
startProfiling() |
void |
stopAllocCounting() |
void |
stopProfiling() |
void |
waitForIdle(Runnable arg0) |
void |
waitForIdleSync() |
Activity |
waitForMonitor(Instrumentation.ActivityMonitor arg0) |
Activity |
waitForMonitorWithTimeout(Instrumentation.ActivityMonitor arg0, long arg1) |
|
From class java.lang.Object
Object |
clone() |
boolean |
equals(Object arg0) |
void |
finalize() |
final Class<?> |
getClass() |
int |
hashCode() |
final void |
notify() |
final void |
notifyAll() |
String |
toString() |
final void |
wait(long arg0, int arg1) |
final void |
wait(long arg0) |
final void |
wait() |
|
Public constructors
MonitoringInstrumentation
MonitoringInstrumentation ()
Public methods
callActivityOnCreate
void callActivityOnCreate (Activity activity,
Bundle bundle)
Parameters |
activity |
Activity
|
bundle |
Bundle
|
callActivityOnDestroy
void callActivityOnDestroy (Activity activity)
Parameters |
activity |
Activity
|
callActivityOnPause
void callActivityOnPause (Activity activity)
Parameters |
activity |
Activity
|
callActivityOnRestart
void callActivityOnRestart (Activity activity)
Parameters |
activity |
Activity
|
callActivityOnResume
void callActivityOnResume (Activity activity)
Parameters |
activity |
Activity
|
callActivityOnStart
void callActivityOnStart (Activity activity)
Parameters |
activity |
Activity
|
callActivityOnStop
void callActivityOnStop (Activity activity)
Parameters |
activity |
Activity
|
callApplicationOnCreate
void callApplicationOnCreate (Application app)
Parameters |
app |
Application
|
execStartActivities
void execStartActivities (Context who,
IBinder contextThread,
IBinder token,
Activity target,
Intent[] intents,
Bundle options)
Parameters |
who |
Context
|
contextThread |
IBinder
|
token |
IBinder
|
target |
Activity
|
intents |
Intent
|
options |
Bundle
|
execStartActivity
Instrumentation.ActivityResult execStartActivity (Context who,
IBinder contextThread,
IBinder token,
Activity target,
Intent intent,
int requestCode,
Bundle options)
Parameters |
who |
Context
|
contextThread |
IBinder
|
token |
IBinder
|
target |
Activity
|
intent |
Intent
|
requestCode |
int
|
options |
Bundle
|
Returns |
Instrumentation.ActivityResult |
|
execStartActivity
Instrumentation.ActivityResult execStartActivity (Context who,
IBinder contextThread,
IBinder token,
Activity target,
Intent intent,
int requestCode)
Parameters |
who |
Context
|
contextThread |
IBinder
|
token |
IBinder
|
target |
Activity
|
intent |
Intent
|
requestCode |
int
|
Returns |
Instrumentation.ActivityResult |
|
execStartActivity
Instrumentation.ActivityResult execStartActivity (Context who,
IBinder contextThread,
IBinder token,
Fragment target,
Intent intent,
int requestCode,
Bundle options)
Parameters |
who |
Context
|
contextThread |
IBinder
|
token |
IBinder
|
target |
Fragment
|
intent |
Intent
|
requestCode |
int
|
options |
Bundle
|
Returns |
Instrumentation.ActivityResult |
|
finish
void finish (int resultCode,
Bundle results)
确保仪器退出前完成在此仪器中启动的所有活动。
覆盖此方法的子类应完成其处理,然后调用super.finish来调用此逻辑。 在退出前不等待所有活动完成()会导致设备宽泛不稳定。
Parameters |
resultCode |
int
|
results |
Bundle
|
newActivity
Activity newActivity (Class<?> clazz,
Context context,
IBinder token,
Application application,
Intent intent,
ActivityInfo info,
CharSequence title,
Activity parent,
String id,
Object lastNonConfigurationInstance)
Parameters |
clazz |
Class
|
context |
Context
|
token |
IBinder
|
application |
Application
|
intent |
Intent
|
info |
ActivityInfo
|
title |
CharSequence
|
parent |
Activity
|
id |
String
|
lastNonConfigurationInstance |
Object
|
Throws |
InstantiationException |
|
IllegalAccessException |
|
onCreate
void onCreate (Bundle arguments)
设置生命周期监控和参数注册表。
子类必须调用onCreate()。 这个onCreate方法不会调用start(),如果需要,它是子类的责任。
Parameters |
arguments |
Bundle
|
onDestroy
void onDestroy ()
onException
boolean onException (Object obj,
Throwable e)
Parameters |
obj |
Object
|
e |
Throwable
|
onStart
void onStart ()
onStart()的这个实现将保证应用程序的onCreate方法在返回时完成。
在执行任何接触应用程序的代码和它的状态之前,子类应该调用super.onStart()。
startActivitySync
Activity startActivitySync (Intent intent)
Protected methods
dumpThreadStateToOutputs
void dumpThreadStateToOutputs (String outputFileName)
Parameters |
outputFileName |
String
|
getThreadState
String getThreadState ()
specifyDexMakerCacheProperty
void specifyDexMakerCacheProperty ()
waitForActivitiesToComplete
void waitForActivitiesToComplete ()
确保我们已经onStopped()所有onStarted()的活动。
根据Activity的合同,这个过程不会在onStart和onStop之间产生冲突。 打破这个契约(如果你愿意的话,finish()会导致不良行为(包括完全重启system_server))。
我们给应用程序2秒钟停止所有活动,然后继续。