I'm trying to figure out how to test onSavedInstance using the newer AndroidJunit4 and Activity Rules.
@RunWith(AndroidJUnit4.class)
public class MyViewActivityTest{
@Rule
public UiThreadTestRule uiThreadTestRule = new UiThreadTestRule();
@Rule
public ActivityTestRule<MyViewActivity> mActivityRule = new ActivityTestRule<>(MyViewActivity.class);
@UiThreadTest
@Test
public void testOnSavedIntanceState() {
uiThreadTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
Intent in = new Intent();
MyViewActivity activity = mActivityRule.launchActivity(in);
activity.finish();
activity.recreate();
}
});
}
I get an error not sure if I am barking up the right tree.
java.lang.IllegalStateException: Must be called from main thread at android.app.Activity.recreate(Activity.java:4620)