android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry Java Examples
The following examples show how to use
android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUtils.java From simple-stack with Apache License 2.0 | 6 votes |
/** * 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]; }
Example #2
Source File: ActivityUtils.java From material-activity-chooser with Apache License 2.0 | 6 votes |
/** * 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]; }
Example #3
Source File: ItClickerActivity.java From SmoothClicker with MIT License | 6 votes |
/** * 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; }
Example #4
Source File: ItIntroScreensActivity.java From SmoothClicker with MIT License | 6 votes |
/** * 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; }
Example #5
Source File: ActivityIdlingResource.java From px-android with MIT License | 5 votes |
private Activity getActivityInstance() { final Activity[] mActivity = new Activity[1]; final Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED); Iterator<Activity> iterator = resumedActivities.iterator(); if (iterator.hasNext()) { mActivity[0] = iterator.next(); } return mActivity[0]; }
Example #6
Source File: PermissiveTestRule.java From permissive with Apache License 2.0 | 5 votes |
@Override protected void afterActivityFinished() { super.afterActivityFinished(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); ActivityLifecycleMonitorRegistry.getInstance().removeLifecycleCallback(activityLifecycleCallback); PermissiveTesting.release(); alreadyInitialized = false; }
Example #7
Source File: PermissiveTestRule.java From permissive with Apache License 2.0 | 5 votes |
@Override protected void beforeActivityLaunched() { if (alreadyInitialized) return; grantAllPermissions(); PermissiveTesting permissiveTesting = PermissiveTesting.init(); for(String fakePerm : fakePermissions) { permissiveTesting.grantFakePermission(fakePerm); } ActivityLifecycleMonitorRegistry.getInstance().addLifecycleCallback(activityLifecycleCallback); super.beforeActivityLaunched(); }
Example #8
Source File: ItServiceClicker.java From SmoothClicker with MIT License | 5 votes |
/** * 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(); } } }); return mResumedActivity; }
Example #9
Source File: ItNotificationsManager.java From SmoothClicker with MIT License | 5 votes |
/** * 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(); } } }); return mResumedActivity; }
Example #10
Source File: ItSettingsActivity.java From SmoothClicker with MIT License | 5 votes |
/** * 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(); } } }); return mResumedActivity; }
Example #11
Source File: EspCloseAllActivitiesFunction.java From espresso-macchiato with MIT License | 5 votes |
public static Set<Activity> getActivitiesInStages(Stage... stages) { final Set<Activity> activities = Sets.newHashSet(); final ActivityLifecycleMonitor instance = ActivityLifecycleMonitorRegistry.getInstance(); for (Stage stage : stages) { activities.addAll(instance.getActivitiesInStage(stage)); } return activities; }
Example #12
Source File: BaseInstrumentedTest.java From mangosta-android with Apache License 2.0 | 5 votes |
protected Activity getCurrentActivity() { InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { public void run() { Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED); if (resumedActivities.iterator().hasNext()) { mCurrentActivity = resumedActivities.iterator().next(); } } }); return mCurrentActivity; }
Example #13
Source File: Test1.java From mobile-android-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
static Activity getCurrentActivity() { ActivityLifecycleMonitor registry = ActivityLifecycleMonitorRegistry.getInstance(); Collection<Activity> activities = registry.getActivitiesInStage(Stage.RESUMED); if (activities.size() > 0) { return (Activity) activities.toArray()[0]; } return null; }
Example #14
Source File: MapActivityTest.java From mobile-android-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
static Activity getCurrentActivity() { ActivityLifecycleMonitor registry = ActivityLifecycleMonitorRegistry.getInstance(); Collection<Activity> activities = registry.getActivitiesInStage(Stage.RESUMED); if (activities.size() > 0) { return (Activity) activities.toArray()[0]; } return null; }
Example #15
Source File: CurrentActivityFetcher.java From px-android with MIT License | 5 votes |
@Override public void run() { final Collection<Activity> resumedActivity = ActivityLifecycleMonitorRegistry.getInstance() .getActivitiesInStage(Stage.RESUMED); if (resumedActivity.iterator().hasNext()) { currentActivity = resumedActivity.iterator().next(); } }
Example #16
Source File: WaitActivityIsResumedIdlingResource.java From openshop.io-android with MIT License | 4 votes |
public WaitActivityIsResumedIdlingResource(String activityToWaitClassName) { instance = ActivityLifecycleMonitorRegistry.getInstance(); this.activityToWaitClassName = activityToWaitClassName; }
Example #17
Source File: ActivityFinisher.java From material-activity-chooser with Apache License 2.0 | 4 votes |
ActivityFinisher() { this.mLifecycleMonitor = ActivityLifecycleMonitorRegistry.getInstance(); }
Example #18
Source File: ActivityFinisher.java From CleanGUITestArchitecture with MIT License | 4 votes |
private ActivityFinisher() { this.activityLifecycleMonitor = ActivityLifecycleMonitorRegistry.getInstance(); }