Kamil Krzyk, thanks for sharing!
I don’t believe the following is a good way of getting the current activity though
public Activity getCurrentActivity() { return ((TestApplication) InstrumentationRegistry. getTargetContext().getApplicationContext()).getCurrentActivity(); }
Inside the Espresso test, one can do the following which is better:
@Nullable
protected Activity getActivityInstance() {
final Activity[] currentActivity = new Activity[1];
getInstrumentation().runOnMainSync(() -> {
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
.getActivitiesInStage(Stage.RESUMED);
for (Activity act : resumedActivities) {
currentActivity[0] = act;
}
});
return currentActivity[0];
}
Do you have a Github repository for me to understand your tutorial better?