I was unit testing a simple app today. I have a method
protected void onRestart() {
disp.setText("The numbers you entered were");
super.onRestart();
}
And in my test case i'm using
public void testRestart(){
String dispText = disp.getText().toString();
getInstrumentation().callActivityOnStop(mActivity);
assertEquals(dispText, disp.getText().toString());
}
The assertion returns true meaning that the text isn't changed. However when i use
public void testRestart(){
String dispText = disp.getText().toString();
getInstrumentation().callActivityOnRestart(mActivity);
assertEquals(dispText, disp.getText().toString());
}
the assertion is false as expected.
According to the activity lifecycle onRestart() should always be called after onStop() if the user navigates away from the activity.
Shouldn't the onRestart() method be called after onStop() ? Or does calling getInstrumentation().callActivityOnStop(mActivity);
kill the activity, instead of just stopping it ?