Skip to content

Instantly share code, notes, and snippets.

@elevenetc
Last active October 26, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elevenetc/df58a6ee4b776edb67c2 to your computer and use it in GitHub Desktop.
Save elevenetc/df58a6ee4b776edb67c2 to your computer and use it in GitHub Desktop.
Getting current activity
//http://qathread.blogspot.de/2014/09/discovering-espresso-for-android-how-to.html
//http://stackoverflow.com/questions/25998659/espresso-how-can-i-check-if-an-activity-is-launched-after-performing-a-certain
public Activity getActivityInstance(){
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
if (resumedActivities.iterator().hasNext()){
currentActivity = resumedActivities.iterator().next();
}
}
});
return currentActivity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment