本文整理匯總了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();
}