當前位置: 首頁>>代碼示例>>Java>>正文


Java ActivityLifecycleMonitorRegistry類代碼示例

本文整理匯總了Java中android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry的典型用法代碼示例。如果您正苦於以下問題:Java ActivityLifecycleMonitorRegistry類的具體用法?Java ActivityLifecycleMonitorRegistry怎麽用?Java ActivityLifecycleMonitorRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ActivityLifecycleMonitorRegistry類屬於android.support.test.runner.lifecycle包,在下文中一共展示了ActivityLifecycleMonitorRegistry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCurrentActivity

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity() throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:TestUtils.java

示例2: getCurrentActivity

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity()
        throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if(resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
開發者ID:Zhuinden,項目名稱:simple-stack,代碼行數:25,代碼來源:TestUtils.java

示例3: findAllInStage

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@NonNull
public List<Activity> findAllInStage(final Stage activityStage) {
    final List<Activity> foundActivities = new ArrayList<>();
    Runnable task = new Runnable() {
        @Override
        public void run() {
            foundActivities.addAll(ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(activityStage));
        }
    };

    if (Looper.myLooper() != Looper.getMainLooper()) {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(task);
    } else {
        task.run();
    }
    return foundActivities;
}
 
開發者ID:PGSSoft,項目名稱:espresso-doppio,代碼行數:18,代碼來源:ComponentFinder.java

示例4: perform

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = (Activity) view.getContext();
    activity.setRequestedOrientation(orientation);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
開發者ID:sevenli777,項目名稱:AppIntro,代碼行數:18,代碼來源:OrientationChangeAction.java

示例5: loader_manager_is_retained_across_config_changes

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().fragment.loaderManager;
    final TestActivityWithFragment firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivityWithFragment secondActivity = (TestActivityWithFragment) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.fragment.loaderManager;

            assertNotSame(firstActivity.fragment, secondActivity.fragment);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
開發者ID:evant,項目名稱:loadie,代碼行數:23,代碼來源:LoaderManagerProviderFragmentTest.java

示例6: loader_manager_is_retained_across_config_changes

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().loaderManager;
    final Activity firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivity secondActivity = (TestActivity) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.loaderManager;

            assertNotSame(firstActivity, secondActivity);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
開發者ID:evant,項目名稱:loadie,代碼行數:23,代碼來源:LoaderManagerProviderActivityTest.java

示例7: loader_manager_is_retained_across_config_changes

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().fragment.fragment.loaderManager;
    final TestActivityWithNestedFragment firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivityWithNestedFragment secondActivity = (TestActivityWithNestedFragment) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.fragment.fragment.loaderManager;

            assertNotSame(firstActivity.fragment.fragment, secondActivity.fragment.fragment);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
開發者ID:evant,項目名稱:loadie,代碼行數:23,代碼來源:LoaderManagerProviderNestedFragmentTest.java

示例8: loader_manager_is_retained_across_config_changes

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().controller.loaderManager;
    final Activity firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivity secondActivity = (TestActivity) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.controller.loaderManager;

            assertNotSame(firstActivity, secondActivity);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
開發者ID:evant,項目名稱:loadie,代碼行數:23,代碼來源:LoaderManagerProviderControllerTest.java

示例9: startActivitySync

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public Activity startActivitySync(@NonNull Intent intent) {
    ComponentName componentName = intent.getComponent();
    Class<? extends Activity> cls;
    try {
        cls = (Class<? extends Activity>) Class.forName(componentName.getClassName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    Activity activity = Robolectric.setupActivity(cls);
    ActivityLifecycleMonitorRegistry.registerInstance(activityLifecycleMonitor);
    activityLifecycleMonitor.signalLifecycleChange(Stage.CREATED, activity);
    activityLifecycleMonitor.signalLifecycleChange(Stage.STARTED, activity);
    activityLifecycleMonitor.signalLifecycleChange(Stage.RESUMED, activity);
    return activity;
}
 
開發者ID:maskarade,項目名稱:Robolectric-Instrumentation,代碼行數:19,代碼來源:InstrumentationRegistry.java

示例10: getActivityInstance

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
/**
 * Retrieves the on going activity
 * @return Activity - The current activity
 */
private static Activity getActivityInstance(){
    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(Stage.RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                mResumedActivity = (Activity) resumedActivities.iterator().next();
            }
            if (resumedActivities.size() <= 0 ){
                mResumedActivity = null;
            }
        }
    });
    return mResumedActivity;
}
 
開發者ID:pylapp,項目名稱:SmoothClicker,代碼行數:20,代碼來源:ItIntroScreensActivity.java

示例11: getCurrentActivity

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
/**
 * Gets an instance of the currently active (displayed) activity.
 * @param activityTestRule test rule
 * @param <T> activity class
 * @return activity instance
 */
public static  <T extends Activity> T getCurrentActivity(@NonNull ActivityTestRule activityTestRule) {
    getInstrumentation().waitForIdleSync();
    final Activity[] activity = new Activity[1];
    try {
        activityTestRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                java.util.Collection<Activity> activites = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
                activity[0] = Iterables.getOnlyElement(activites);
            }});
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    //noinspection unchecked
    return (T) activity[0];
}
 
開發者ID:zawadz88,項目名稱:material-activity-chooser,代碼行數:23,代碼來源:ActivityUtils.java

示例12: takeScreenshot

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
void takeScreenshot(final String path)
{
    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable()
    {
        @Override
        public void run()
        {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
            Iterator<Activity> iterator = resumedActivities.iterator();

            if (iterator.hasNext())
            {
                Activity activity = iterator.next();

                try
                {
                    takeScreenshot(activity, path);
                }
                catch (Exception e)
                {
                    // ignore
                }
            }
        }
    });
}
 
開發者ID:mauriciotogneri,項目名稱:green-coffee,代碼行數:27,代碼來源:ScreenCapture.java

示例13: perform

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = getActivity(view);
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            activity.setRequestedOrientation(orientation);
        }
    });
    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    uiController.loopMainThreadUntilIdle();
    SystemClock.sleep(512);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
開發者ID:seguemodev,項目名稱:Meducated-Ninja,代碼行數:18,代碼來源:OrientationChangeAction.java

示例14: getActivity

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
@Override
public TestActivity getActivity() {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
            if (activities.isEmpty()) {
                mActivity = null;
            } else {
                mActivity = (TestActivity) activities.iterator().next();
            }
        }
    };
    if (Looper.myLooper() == Looper.getMainLooper()) {
        runnable.run();
    } else {
        getInstrumentation().runOnMainSync(runnable);
        getInstrumentation().waitForIdleSync();
    }

    return mActivity == null ? super.getActivity() : mActivity;
}
 
開發者ID:nhaarman,項目名稱:Triad,代碼行數:23,代碼來源:TestActivityInstrumentationTestCase.java

示例15: getDisplayedActivityInstance

import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; //導入依賴的package包/類
public Activity getDisplayedActivityInstance() {
	final Activity[] currentActivity = new Activity[1];
	getInstrumentation().runOnMainSync(new Runnable() {
		public void run() {
			Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
			if (resumedActivities.iterator().hasNext()) {
				currentActivity[0] = resumedActivities.iterator().next();
			}
		}
	});

	return currentActivity[0];
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:PubkeyListActivityTest.java


注:本文中的android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。