本文整理汇总了Java中android.app.Instrumentation.ActivityMonitor方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.ActivityMonitor方法的具体用法?Java Instrumentation.ActivityMonitor怎么用?Java Instrumentation.ActivityMonitor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Instrumentation
的用法示例。
在下文中一共展示了Instrumentation.ActivityMonitor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForOverlay
import android.app.Instrumentation; //导入方法依赖的package包/类
void waitForOverlay(long millis) {
if (!testSystemLayer()) {
Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(MainActivity.class.getCanonicalName(),
null, false);
getInstrumentation().addMonitor(monitor);
getActivityRule().launchActivity(new Intent(getApplication(), MainActivity.class));
try {
monitor.waitForActivityWithTimeout(5000);
} finally {
getInstrumentation().removeMonitor(monitor);
}
}
try {
Thread.currentThread().sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例2: recreateCurrentActivity
import android.app.Instrumentation; //导入方法依赖的package包/类
public void recreateCurrentActivity() {
if( mActivity != null )
{
final Instrumentation.ActivityMonitor monitor =
new Instrumentation.ActivityMonitor(mActivity.getClass().getName(), null, false);
mInstrumentation.addMonitor(monitor);
mInstrumentation.runOnMainSync(new Runnable()
{
@Override
public void run()
{
mActivity.recreate();
}
});
afterActivityFinished();
mInstrumentation.waitForIdleSync();
beforeActivityLaunched();
//noinspection unchecked
mActivity = checkNotNull((T) monitor.waitForActivity(), "current activity shouldn't be null!");
afterActivityLaunched();
mInstrumentation.removeMonitor(monitor);
}
}
示例3: startSecondActivity
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void startSecondActivity() {
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
debugOverlay = new DebugOverlay.Builder(getApplication())
.allowSystemLayer(testSystemLayer())
.build();
debugOverlay.install();
}
});
waitForOverlay();
Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(ScrollingActivity.class.getCanonicalName(),
null, false);
getInstrumentation().addMonitor(monitor);
try {
onView(withId(com.ms_square.debugoverlay.sample.R.id.fab)).perform(click());
Activity nextActivity = monitor.waitForActivityWithTimeout(5000);
assertThat(nextActivity, Matchers.is(Matchers.notNullValue()));
takeActivityScreenShot(nextActivity);
nextActivity.finish();
} finally {
getInstrumentation().removeMonitor(monitor);
}
}
示例4: menuClickProfileGoesToProfile
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void menuClickProfileGoesToProfile() throws Exception {
Instrumentation.ActivityMonitor activityMonitor = getInstrumentation()
.addMonitor(ProfileActivity.class.getName(), null, false);
onView(withId(R.id.action_profile)).perform(click());
ProfileActivity targetActivity = (ProfileActivity) activityMonitor.waitForActivity();
assertNotNull("Target Activity is not launched", targetActivity);
}
示例5: menuClickFriendsGoesToFriends
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void menuClickFriendsGoesToFriends() throws Exception {
Instrumentation.ActivityMonitor activityMonitor = getInstrumentation()
.addMonitor(FriendsActivity.class.getName(), null, false);
onView(withId(R.id.action_friends)).perform(click());
FriendsActivity targetActivity = (FriendsActivity) activityMonitor.waitForActivity();
assertNotNull("Target Activity is not launched", targetActivity);
}
示例6: openActivity
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test (timeout = 10000)
public void openActivity(){
Instrumentation.ActivityMonitor activityMonitor = new Instrumentation.ActivityMonitor(SelectPictureActivity.class.getName(), null, false);
instrumentation.addMonitor(activityMonitor);
onView(withId(R.id.changePictureButton)).perform(click());
Activity launchedActivity = instrumentation.waitForMonitor(activityMonitor);
Assert.assertEquals(launchedActivity.getClass(), SelectPictureActivity.class);
launchedActivity.finish();
}