I am using Robotium to functionally test an Android app. I'd like to test the onResume behaviour after onDestroy has been called. This post hints on using Instrumentation, but i can't get it to work. I have included the following, but this fails with an IllegalStateException. Is it possible to destroy the app and restart it?
public class MainActivityFunctionalTest extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public MainActivityFunctionalTest() {
super(MainActivity.class);
}
public void testActionList() {
getInstrumentation().callActivityOnDestroy(solo.getCurrentActivity());
...
}
Results in the following exception:
java.lang.IllegalStateException: Must be called from main thread of process at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1373) at android.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:1825) at android.app.Activity.performDestroy(Activity.java:5171) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1109) at nl.handypages.trviewer.test.MainActivityFunctionalTest.testActionList(MainActivityFunctionalTest.java:81) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)