本文整理汇总了Java中android.app.Instrumentation.waitForIdleSync方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.waitForIdleSync方法的具体用法?Java Instrumentation.waitForIdleSync怎么用?Java Instrumentation.waitForIdleSync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Instrumentation
的用法示例。
在下文中一共展示了Instrumentation.waitForIdleSync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeActivity
import android.app.Instrumentation; //导入方法依赖的package包/类
private static boolean closeActivity(Instrumentation instrumentation) throws Exception {
final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
if (activities.size() > 0) {
final Activity activity = activities.iterator().next();
activity.finish();
return true;
} else {
return false;
}
}
});
if (activityClosed) {
instrumentation.waitForIdleSync();
}
return activityClosed;
}
示例2: startActivity
import android.app.Instrumentation; //导入方法依赖的package包/类
private void startActivity() {
if (launched)
return;
Instrumentation instrumentation = getInstrumentation();
Intent intent = new Intent(getInstrumentation()
.getTargetContext(), AndroidNativeActivity.class);
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity = instrumentation.startActivitySync(intent);
launched = true;
instrumentation.waitForIdleSync();
sleep(5000);
}
示例3: searchFragmentShouldCollectDisposablesAndReleaseThemInOnDestroy
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void searchFragmentShouldCollectDisposablesAndReleaseThemInOnDestroy() {
CompositeDisposable composite = new CompositeDisposable();
decorate().searchFragmentSubcomponent().withCompositeDisposable(() -> composite);
final MainActivity activity = rule.launchActivity(null);
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.runOnMainSync(() ->
{
((ViewPager)activity.findViewById(R.id.container)).setCurrentItem(2);
assertEquals(1, composite.size());
activity.finish();
});
instrumentation.waitForIdleSync();
SystemClock.sleep(500);
assertTrue(composite.isDisposed());
}
示例4: waitInner
import android.app.Instrumentation; //导入方法依赖的package包/类
private static void waitInner(ReactBridgeIdleSignaler idleSignaler, long timeToWait) {
// TODO gets broken in gradle, do we need it?
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
long startTime = SystemClock.uptimeMillis();
boolean bridgeWasIdle = false;
while (SystemClock.uptimeMillis() - startTime < timeToWait) {
boolean bridgeIsIdle = idleSignaler.isBridgeIdle();
if (bridgeIsIdle && bridgeWasIdle) {
return;
}
bridgeWasIdle = bridgeIsIdle;
long newTimeToWait = Math.max(1, timeToWait - (SystemClock.uptimeMillis() - startTime));
idleSignaler.waitForIdle(newTimeToWait);
instrumentation.waitForIdleSync();
}
throw new RuntimeException("Timed out waiting for bridge and UI idle!");
}
示例5: finishActivitySync
import android.app.Instrumentation; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static public void finishActivitySync(Activity activity, Instrumentation instrumentation, boolean doFinish)
{
if (doFinish)
activity.finish();
//give activity one minute to finish
long currentTime = System.currentTimeMillis();
boolean finishTimeout = false;
int activityHash = activity.hashCode();
boolean isDestroyed = false;
while (!isDestroyed && !finishTimeout) {
instrumentation.waitForIdleSync();
finishTimeout = (System.currentTimeMillis() - currentTime) > 140000;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
isDestroyed = activity.isDestroyed();
}else {
isDestroyed = (Boolean)callMethod(null, activity.getWindow(), "isDestroyed", null);
}
}
if (finishTimeout) {
WebtrekkLogging.log("finishActivitySync: finished by timeout. Hash:" + activityHash);
}
}
示例6: removesLocationUpdatesOnStop
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void removesLocationUpdatesOnStop() throws Throwable {
final MainActivity activity = rule.launchActivity(null);
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.runOnMainSync(() -> {
instrumentation.callActivityOnPause(activity);
verify(locationService, times(0)).removeUpdates();
instrumentation.callActivityOnStop(activity);
verify(locationService).removeUpdates();
});
instrumentation.waitForIdleSync();
}
示例7: testActivityChanging
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void testActivityChanging() {
Instrumentation instrumentation = getInstrumentation();
TrackActivityIsStopped callback = new TrackActivityIsStopped("PageExampleActivity");
mApplication.registerActivityLifecycleCallbacks(callback);
//track main activity
initWaitingForTrack(null);
Activity mainActivity = mActivityRule.launchActivity(null);
String URL = waitForTrackedURL();
URLParsel parcel = new URLParsel();
parcel.parseURL(URL);
assertTrue(parcel.getValue("p").contains("Startseite"));
//track first page activity
initWaitingForTrack(null);
onView(withId(R.id.button_page)).perform(click());
URL = waitForTrackedURL();
parcel.parseURL(URL);
assertTrue(parcel.getValue("p").contains("Seite"));
//track next page activity
initWaitingForTrack(null);
onView(withId(R.id.button_next_page)).perform(click());
URL = waitForTrackedURL();
parcel.parseURL(URL);
assertTrue(parcel.getValue("p").contains("NextPage"));
//track first page activity
initWaitingForTrack(null);
//wait while PageExampleActivity is stopped
while (!callback.isStoped()){
instrumentation.waitForIdleSync();
}
pressBack();
URL = waitForTrackedURL();
parcel.parseURL(URL);
assertTrue(parcel.getValue("p").contains("Seite"));
//track main activity
initWaitingForTrack(null);
pressBack();
URL = waitForTrackedURL();
parcel.parseURL(URL);
assertTrue(parcel.getValue("p").contains("Startseite"));
mApplication.unregisterActivityLifecycleCallbacks(callback);
}