I am starting from LoginActivity and after logging in, my app goes to next Activity with a RecyclerView. I need to have a reference to the Recycler View. I am doing this but getting null.
RecyclerView recyclerView = (RecyclerView) loginActivity.getActivity().findViewById(R.id.messages_list);
It is null because loginActivity does not contain the RecyclerView. So, my question is, once I move to the second activity, how can I tell espresso to replace loginActivity with the new activity so that I can do this
RecyclerView recyclerView = (RecyclerView) currentActivity.getActivity().findViewById(R.id.messages_list);
If that is not possible, what other ways are there?
Activity currentActivity;
public Activity getActivityInstance() {
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.iterator().hasNext()) {
currentActivity = (Activity) resumedActivities.iterator().next();
}
}
});
return currentActivity;
}
RecyclerView recyclerView = (RecyclerView) getActivityInstance().findViewById(R.id.messages_list);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With