In both the Testing Fundamentals and the Activity Testing section entitled "Adding state management tests" in the Android developer documentation, it suggests testing activity restarts using:
mActivity.finish();
mActivity = this.getActivity();
Having tried this with the addition of a sleep between the two statements above, I can see that the Activity is not redrawn on the screen when the mActivity = this.getActivity() is executed. My test appears to work, but I am intrigued as to why the Activity isn't redrawn on the screen as this doesn't seem to be mentioned in the API documentation.
I'd be grateful for any insight into this anyone can give. At the point the finish() method is called, the Activity disappears from the screen, but doesn't reappear when the this.getActivity() is called. I've also tried putting an mActivity.setVisible(true) after the getActivity(), but that doesn't help.
My code snippet is now:
...
mActivity.finish();
Thread.sleep(5000);
mActivity = this.getActivity();
Thread.sleep(5000);
...
I've searched extensively, but can't find any explanation of why the Activity doesn't reappear when getActivity() is called.
I've tested this on Android 2.3.5, 2.3.3 and 2.2.2 all with the same result.