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

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

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

Instrumentation.removeMonitor介绍

暂无

代码示例

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

/**
 * Removes the ActivityMonitor
 */
private void stopActivityMonitor(){
  try {
    // Remove the monitor added during startup
    if (activityMonitor != null) {
      inst.removeMonitor(activityMonitor);
      activityMonitor = null;
    }
  } catch (Exception ignored) {}
}

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

/**
 * Removes the AcitivityMonitor
 * 
 * @param activityMonitor the ActivityMonitor to remove
 */

private void removeMonitor(ActivityMonitor activityMonitor){
  try{
    instrumentation.removeMonitor(activityMonitor);	
  }catch (Exception ignored) {}
}

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

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

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

@Override
public void finishActivity() {
  super.finishActivity();
  instrumentation.removeMonitor(welcomeMonitor);
  if (welcomeActivity != null) {
    welcomeActivity.finish();
  }
}

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

/**
 * Removes the ActivityMonitor
 */
private void stopActivityMonitor(){
  try {
    // Remove the monitor added during startup
    if (activityMonitor != null) {
      inst.removeMonitor(activityMonitor);
      activityMonitor = null;
    }
  } catch (Exception ignored) {}
}

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

/**
 * Removes the AcitivityMonitor
 * 
 * @param activityMonitor the ActivityMonitor to remove
 */

private void removeMonitor(ActivityMonitor activityMonitor){
  try{
    instrumentation.removeMonitor(activityMonitor);	
  }catch (Exception ignored) {}
}

代码示例来源:origin: bzsome/VirtualApp-x326

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

代码示例来源:origin: darkskygit/VirtualApp

@Override
public void removeMonitor(ActivityMonitor monitor) {
  base.removeMonitor(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: luili16/UIMocker

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

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

public static final HashSet<Class<? extends Activity>> TARGET_ACTIVITIES = new HashSet<Class<? extends Activity>>();
static {
  TARGET_ACTIVITIES.add(A1.class);
  TARGET_ACTIVITIES.add(A2.class);
  TARGET_ACTIVITIES.add(A3.class);
}

private static final int TIMEOUT = 7000;

public void testRandomActivityStarted() {
  @SuppressWarnings("unused")
  ProgressActivity activity = getActivity();
  final Instrumentation inst = getInstrumentation();
  IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN);
  intentFilter.addCategory("MY_CATEGORY");
  ActivityMonitor monitor = inst.addMonitor(intentFilter, null, false);
  // Wait, before the Activity started
  monitor.waitForActivityWithTimeout(TIMEOUT);
  assertEquals(1, monitor.getHits());
  Activity randomActivity = monitor.getLastActivity();
  Log.d(TAG, "monitor=" + monitor + "   activity=" + randomActivity);
  // Unfortunately, it seems randomActivity is always null even after a match
  if ( randomActivity != null ) {
    assertTrue(TARGET_ACTIVITIES.contains(randomActivity.getClass()));
  }
  inst.removeMonitor(monitor);
}

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

// register activity monitor for the send mail activity
Instrumentation instrumentation = getInstrumentation();
IntentFilter filter = new IntentFilter(Intent.ACTION_SENDTO);
ActivityMonitor monitor = new ActivityMonitor(filter, null, false);
ActivityMonitor soloMonitor = solo.getActivityMonitor();

// Remove the solo monitor, so your monitor is first on the list.
instrumentation.removeMonitor(soloMonitor);
// add your own monitor.
instrumentation.addMonitor(monitor);
// Re-add the solo monitor
instrumentation.addMonitor(soloMonitor);

// click on the "Send Feedback" button (use Robotium here)
solo.clickOnButton(0);

// wait for the send mail activity to start
Activity currentActivity = instrumentation.waitForMonitorWithTimeout(monitor, 5000);
assertNotNull(currentActivity);

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

public static Activity restartActivity(Activity activity, Instrumentation instrumentation, Intent intent){
  String className = activity.getClass().getName();
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(className, null, false);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setClassName(instrumentation.getTargetContext(), className );
  instrumentation.startActivitySync(intent);
  Activity newActivity = instrumentation.waitForMonitor(monitor);
  instrumentation.removeMonitor(monitor);
  return newActivity;
}

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

//set up the filter
final Instrumentation inst = getInstrumentation();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_VIEW);
intentFilter.addDataScheme("http");
intentFilter.addCategory(Intent.CATEGORY_BROWSABLE);

//Set up the monitor
//THE BOOLEAN ON THE END TELLS THE SYTEM TO BLOCK IT FROM OCCURING, you probably want true here
ActivityMonitor monitor = inst.addMonitor(intentFilter, null, true);

assertEquals(0,monitor.getHits()); 

//click the link here with whatever framework you are using
solo. clickOnText("link text")

//Wait for the activity to get hit
monitor.waitForActivityWithTimeout(2000); 

//Here is where you actually check it happened
assertEquals(1, monitor.getHits()); 
inst.removeMonitor(monitor);

代码示例来源: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类方法