当前位置: 首页>>代码示例>>Java>>正文


Java Instrumentation.waitForIdleSync方法代码示例

本文整理汇总了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;
}
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:22,代码来源:EspressoTestUtils.java

示例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);
}
 
开发者ID:benlau,项目名称:androidnative.pri,代码行数:16,代码来源:ExampleActivityTest.java

示例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());
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:17,代码来源:WeatherFragmentTest.java

示例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!");
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:18,代码来源:ReactIdleDetectionUtil.java

示例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);
    }
}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:27,代码来源:WebtrekkBaseSDKTest.java

示例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();
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:13,代码来源:SimpleEspressoTest.java

示例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);
}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:63,代码来源:PageAutoTrackingTest.java


注:本文中的android.app.Instrumentation.waitForIdleSync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。