The solution is to use the method activity.recreate()
, but do not forget to follow this statement, awaiting a state of inaction. My problem with my first attempt was that the test I wrote looked like this:
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
activity.recreate();
}
});
assertThat(activityTestRule.getActivity().getXXX()).isNull();
Where XXX
was the field that I expected would be null if the save / restore state was not processed. But this was not so, because my statement did not expect the completion of the rest task.
So, in my situation, my problem was solved when I simply add an espresso statement that does the job, for example, confirming that the TextView that displayed the field XXX
was empty.
, , Espresso, , . /. . :
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
activity.recreate();
}
});
onView(withText("a string depending on XXX value")).check(doesNotExist());
, , , activity.recreate()
, . , .