Issue
In our Espresso tests, we need to customize the launch intent to pass custom extras and so on. Therefore, we set the launchActivity flag to false:
@Rule
public final ActivityTestRule<CreateQuoteActivity> mActivityRule = new ActivityTestRule<>(
CreateQuoteActivity.class, true, false
);
Now, I want to get a reference to the activity under test. If that flag was true, I would use mActivityRule.getActivity(). However, now mActivityRule.getActivity() returns null.
How can I get a reference to the activity?
Solution
If you have set that launchActivity to false, you only have access to the activity when you actually go ahead and launch it.
So, your activity context is right there:
final CreateQuoteActivity activity = mActivityRule.launchActivity(mIntent);
Answered By - espinchi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.