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

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

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

Instrumentation.startActivitySync介绍

暂无

代码示例

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

@Override
public Activity startActivitySync(Intent intent) {
  return base.startActivitySync(intent);
}

代码示例来源: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: bzsome/VirtualApp-x326

@Override
public Activity startActivitySync(Intent intent) {
  return base.startActivitySync(intent);
}

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

@Override
public Activity startActivitySync(Intent intent) {
  return base.startActivitySync(intent);
}

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

@Override
@CallSuper
public Activity startActivitySync(Intent intent) {
  if (DEBUG) {
    Logger.d(TAG,"startActivitySync");
  }
  return mInstrumentation.startActivitySync(intent);
}

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

// Prepare a monitor for your activity
Instrumentation instrumentation = getInstrumentation()
Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(YourClass.class.getName(), null, false);

// Start your activity manually
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(instrumentation.getTargetContext(), YourClass.class.getName());
    instrumentation.startActivitySync(intent);

// Get the started Activity
Activity currentActivity = getInstrumentation().waitForMonitor(monitor);

代码示例来源: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: com.uphyca/android-junit4-robolectric

@SuppressWarnings("unchecked")
public final <T extends Activity> T launchActivityWithIntent(String pkg,
                               Class<T> activityCls,
                               Intent intent) {
  intent.setClassName(pkg, activityCls.getName());
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  T activity = (T) getInstrumentation().startActivitySync(intent);
  getInstrumentation().waitForIdleSync();
  return activity;
}

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

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(instrumentation.getTargetContext(), MyActivity.class.getName());
instrumentation.startActivitySync(intent);

代码示例来源: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: AndrewReitz/android-spock

/** Launch the activity if needed. */
 @SuppressWarnings("unchecked")
 private void launchActivity() {
  if (activity != null && ActivityRunMode.SPECIFICATION.equals(activityRunMode)) return;

  String targetPackage = instrumentation.getTargetContext().getPackageName();
  Intent intent = getLaunchIntent(targetPackage, activityClass, bundleCreator);

  activity = instrumentation.startActivitySync(intent);
  instrumentation.waitForIdleSync();
 }
}

代码示例来源:origin: anupcowkur/MVPSample

@SuppressWarnings("unchecked") // Guarded by generics at the constructor.
  private void launchActivity() {
    if (activity != null) return;

    Instrumentation instrumentation = fetchInstrumentation();

    String targetPackage = instrumentation.getTargetContext().getPackageName();
    Intent intent = getLaunchIntent(targetPackage, activityClass);

    activity = (T) instrumentation.startActivitySync(intent);
    instrumentation.waitForIdleSync();
  }
}

代码示例来源:origin: appium/appium-espresso-driver

public static void startActivity(String activity, @Nullable String waitActivity,
                   @Nullable Long waitDuration) {
    logger.info(String.format("Starting activity '%s'", activity));
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    String fullyQualifiedAppActivity = getFullyQualifiedActivityName(instrumentation, activity);
    String fullyQualifiedWaitActivity = isBlank(waitActivity)
        ? fullyQualifiedAppActivity
        : getFullyQualifiedActivityName(instrumentation, waitActivity);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(instrumentation.getTargetContext(), fullyQualifiedAppActivity);
    Instrumentation.ActivityMonitor activityStateMonitor = instrumentation
        .addMonitor(fullyQualifiedWaitActivity, null, false);
    instrumentation.startActivitySync(intent);
    if (waitDuration == null) {
      waitDuration = ACTIVITY_STARTUP_TIMEOUT;
    }
    Activity currentActivity = instrumentation.waitForMonitorWithTimeout(activityStateMonitor, waitDuration);
    if (currentActivity == null) {
      throw new IllegalStateException(String.format("Activity '%s' was unable to start within %sms timeout",
          fullyQualifiedWaitActivity, waitDuration));
    }
    logger.info(String.format("Activity '%s' started", currentActivity.getLocalClassName()));
  }
}

相关文章

Instrumentation类方法