我试图弄清楚如何使用较新的 AndroidJunit4 和活动规则测试 onSavedInstance。
@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();
}
});
}
我收到一个错误,不确定我是否在吠叫正确的树。
java.lang.IllegalStateException: 必须从 android.app.Activity.recreate(Activity.java:4620) 的主线程调用