android.app.Instrumentation.addMonitor()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中android.app.Instrumentation.addMonitor()方法的一些代码示例,展示了Instrumentation.addMonitor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.addMonitor()方法的具体详情如下:
包路径:android.app.Instrumentation
类名称:Instrumentation
方法名:addMonitor

Instrumentation.addMonitor介绍

暂无

代码示例

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public ActivityMonitor addMonitor(IntentFilter filter, ActivityResult result, boolean block) {
  return base.addMonitor(filter, result, block);
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public void addMonitor(ActivityMonitor monitor) {
  base.addMonitor(monitor);
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public ActivityMonitor addMonitor(String cls, ActivityResult result, boolean block) {
  return base.addMonitor(cls, result, block);
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * Creates a new ActivityMonitor and returns it
 * 
 * @return an ActivityMonitor
 */
private ActivityMonitor getActivityMonitor(){
  IntentFilter filter = null;
  ActivityMonitor activityMonitor = instrumentation.addMonitor(filter, null, false);
  return activityMonitor;
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * This is were the activityMonitor is set up. The monitor will keep check
 * for the currently active activity.
 */
private void setupActivityMonitor() {
  if(config.trackActivities){
    try {
      IntentFilter filter = null;
      activityMonitor = inst.addMonitor(filter, null, false);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: stephentuso/welcome-android

@Before
public void initActivity() {
  instrumentation = InstrumentationRegistry.getInstrumentation();
  Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(TestActivity.class.getName(), null, false);
  instrumentation.addMonitor(monitor);
  Intent intent = new Intent(instrumentation.getTargetContext(), TestActivity.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  instrumentation.startActivitySync(intent);
  activity = instrumentation.waitForMonitor(monitor);
  assertNotNull(activity);
}

代码示例来源:origin: stephentuso/welcome-android

@Override
public void initActivity() {
  super.initActivity();
  welcomeMonitor = new Instrumentation.ActivityMonitor(DefaultWelcomeActivity.class.getName(), null, false);
  instrumentation.addMonitor(welcomeMonitor);
  new WelcomeHelper(activity, DefaultWelcomeActivity.class).forceShow();
  welcomeActivity = (WelcomeActivity) instrumentation.waitForMonitor(welcomeMonitor);
}

代码示例来源:origin: stephentuso/welcome-android

@Test
public void testForceShow() {
  ActivityMonitor monitor = new ActivityMonitor(DefaultWelcomeActivity.class.getName(), null, false);
  instrumentation.addMonitor(monitor);
  helper.forceShow();
  Activity welcomeActivity = instrumentation.waitForMonitor(monitor);
  assertNotNull(welcomeActivity);
}

代码示例来源:origin: stephentuso/welcome-android

@Test
public void testShow() {
  ActivityMonitor monitor = new ActivityMonitor(DefaultWelcomeActivity.class.getName(), null, false);
  instrumentation.addMonitor(monitor);
  String key = WelcomeUtils.getKey(DefaultWelcomeActivity.class);
  WelcomeSharedPreferencesHelper.storeWelcomeCompleted(activity, key);
  assertFalse(helper.show(null));
  assertFalse(helper.show(new Bundle()));
  WelcomeSharedPreferencesHelper.removeWelcomeCompleted(activity, key);
  assertTrue(helper.show(null));
  assertFalse(helper.show(null));
  Activity welcomeActivity = instrumentation.waitForMonitor(monitor);
  assertNotNull(welcomeActivity);
  WelcomeSharedPreferencesHelper.removeWelcomeCompleted(activity, key);
  Bundle state = new Bundle();
  helper.onSaveInstanceState(state);
  assertFalse(helper.show(state));
}

代码示例来源:origin: com.jayway.android.robotium/robotium-solo

/**
 * Creates a new ActivityMonitor and returns it
 * 
 * @return an ActivityMonitor
 */
private ActivityMonitor getActivityMonitor(){
  IntentFilter filter = null;
  ActivityMonitor activityMonitor = instrumentation.addMonitor(filter, null, false);
  return activityMonitor;
}

代码示例来源:origin: takahirom/PreLollipopTransition

public void testListClick() throws InterruptedException {
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(SubActivity.class.getName(), null, false);
  Spoon.screenshot(getActivity(), "init");
  // listviewactivity -> subactivity
  final ListView listView = (ListView) getActivity().findViewById(R.id.list);
  instrumentation.waitForIdleSync();
  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      assertTrue(listView.performItemClick(listView.getChildAt(0), 0, 0));
    }
  });
  Activity detailActivity = instrumentation.waitForMonitor(monitor);
  // Wait for animation
  Thread.sleep(2000l);
  instrumentation.waitForIdleSync();
  Spoon.screenshot(detailActivity, "listview_transition");
  // subactivity -> listviewactivity
  sendKeys(KeyEvent.KEYCODE_BACK);
  // Wait for animation
  Thread.sleep(2000l);
  instrumentation.waitForIdleSync();
  Spoon.screenshot(getActivity(), "listview_transition_backpress");
}

代码示例来源:origin: takahirom/PreLollipopTransition

public void testGoSubActivity() throws InterruptedException {
  Spoon.screenshot(getActivity(), "init");
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(SubActivity.class.getName(), null, false);
  final ImageView imageView = (ImageView) getActivity().findViewById(R.id.imageView);
  instrumentation.waitForIdleSync();
  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      assertTrue(imageView.performClick());
    }
  });
  Activity activity = instrumentation.waitForMonitor(monitor);
  // Verify new activity was shown.
  ANDROID.assertThat(monitor).hasHits(1);
  // Wait for animation
  Thread.sleep(2000l);
  Spoon.screenshot(activity, "sub_activity_shown");
  // subactivity -> mainactivity
  sendKeys(KeyEvent.KEYCODE_BACK);
  // Wait for animation
  Thread.sleep(2000l);
  instrumentation.waitForIdleSync();
  Spoon.screenshot(getActivity(), "main_activity_backed");
}

代码示例来源:origin: takahirom/PreLollipopTransition

public void testGoSubActivity2() throws InterruptedException {
  Spoon.screenshot(getActivity(), "init");
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(SubActivity2.class.getName(), null, false);
  final ImageView imageView = (ImageView) getActivity().findViewById(R.id.imageView2);
  instrumentation.waitForIdleSync();
  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      assertTrue(imageView.performClick());
    }
  });
  Activity activity = instrumentation.waitForMonitor(monitor);
  // Verify new activity was shown.
  ANDROID.assertThat(monitor).hasHits(1);
  // Wait for animation
  Thread.sleep(2000l);
  Spoon.screenshot(activity, "sub_activity_shown");
  // subactivity -> mainactivity
  sendKeys(KeyEvent.KEYCODE_BACK);
  // Wait for animation
  Thread.sleep(2000l);
  instrumentation.waitForIdleSync();
  Spoon.screenshot(getActivity(), "main_activity_backed");
}

代码示例来源:origin: luili16/UIMocker

@Override
@CallSuper
public void addMonitor(Instrumentation.ActivityMonitor monitor) {
  if (DEBUG) {
    Logger.d(TAG,"registerMonitor");
  }
  mInstrumentation.addMonitor(monitor);
}

代码示例来源:origin: stackoverflow.com

@UiThreadTest
public void testListItemClickStartsActivity() {
  final Instrumentation inst = getInstrumentation();
  final IntentFilter intentFilter = new IntentFilter();
  // here add conditions to your filter, i.e. intentFilter.addAction()
  ActivityMonitor monitor = inst.addMonitor(intentFilter, null, false);
  assertEquals(0, monitor.getHits());
  // here perform desired click on list
  monitor.waitForActivityWithTimeout(5000);
  assertEquals(1, monitor.getHits());
  inst.removeMonitor(monitor);
}

代码示例来源:origin: takahirom/PreLollipopTransition

public void testClearCacheGoSubActivity2() throws InterruptedException {
  Spoon.screenshot(getActivity(), "init");
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(SubActivity2.class.getName(), null, false);

代码示例来源:origin: stackoverflow.com

IntentFilter intF = new IntentFilter("ACTIVITY.THAT.YOU.WANT.TO.LAUNCH");

Instrumentation instrumentation = new Instrumentation();

Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(intF, null, true);
Intent i = new Intent("ACTIVITY.THAT.YOU.WANT.TO.LAUNCH");
instrumentation.startActivitySync(i);

代码示例来源:origin: mttkay/calculon

@Override
public void starts(Class<? extends Activity> activityClass) {
  ActivityMonitor monitor = instrumentation.addMonitor(activityClass.getCanonicalName(),
      null, false);
  performPendingAction();
  assertTrue(instrumentation.checkMonitorHit(monitor, 1));
  Activity lastActivity = monitor.getLastActivity();
  getStoryTestCase().setCurrentActivity(lastActivity);
}

代码示例来源:origin: mttkay/calculon

@Override
  public void startsWithIntentAction(String intentAction) {
    ActivityMonitor monitor = instrumentation.addMonitor(intentAction, null, false);

    performPendingAction();

    assertTrue(instrumentation.checkMonitorHit(monitor, 1));

    Activity lastActivity = monitor.getLastActivity();
    getStoryTestCase().setCurrentActivity(lastActivity);

  }
}

代码示例来源:origin: cattaka/AdapterToolbox

@SuppressWarnings("unchecked")
public static <T extends Activity> T monitorActivity(@NonNull Class<T> activityClass, int timeOut, @NonNull Runnable runnable) {
  Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(activityClass.getCanonicalName(), null, false);
  try {
    InstrumentationRegistry.getInstrumentation().addMonitor(monitor);
    runnable.run();
    return (T) monitor.waitForActivityWithTimeout(timeOut);
  } finally {
    InstrumentationRegistry.getInstrumentation().removeMonitor(monitor);
  }
}

相关文章

Instrumentation类方法