Pablo--

There is support within the TestCase subclasses for running all or parts of
your tests on the UI thread - that might solve your issue.
--Andy

On Jan 28, 2009 11:48 PM, "J. Pablo Fernández" <[email protected]> wrote:


Hello,

At the beginning of my onSaveInstanceState I was calling
super.onSaveInstanceState(outState) and everything was working fine.
But now I wrote an instrumentation test case which basically does:

               Activity activity = getActivity();
               getInstrumentation().callActivityOnStart(activity);
               getInstrumentation().callActivityOnResume(activity);
               Bundle outState = new Bundle();

 getInstrumentation().callActivityOnSaveInstanceState(activity, outState);

and I'm getting this error: "Only the original thread that created a
view hierarchy can touch its views." (stack trace at the bottom). So
I'm wondering, what am I doing wrong here? the test or the app?

Thanks.
--
J. Pablo Fernández <[email protected]> (http://pupeno.com)

PS: The stack trace:

Error in testLoadingAndSavingState:
android.view.ViewRoot$CalledFromWrongThreadException: Only the
original thread that created a view hierarchy can touch its views.
       at android.view.ViewRoot.checkThread(ViewRoot.java:1849)
       at android.view.ViewRoot.invalidateChild(ViewRoot.java:468)
       at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:481)
       at android.view.ViewGroup.invalidateChild(ViewGroup.java:2250)
       at android.view.View.invalidate(View.java:4095)
       at android.widget.TextView.invalidateCursor(TextView.java:2767)
       at android.widget.TextView.access$1300(TextView.java:151)
       at
android.widget.TextView$ChangeWatcher.spanChange(TextView.java:4278)
       at
android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:4304)
       at
android.text.SpannableStringInternal.sendSpanAdded(SpannableStringInternal.java:312)
       at
android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:136)
       at android.text.SpannableString.setSpan(SpannableString.java:46)
       at
android.text.SpannableStringInternal.<init>(SpannableStringInternal.java:50)
       at android.text.SpannableString.<init>(SpannableString.java:30)
       at android.widget.TextView.onSaveInstanceState(TextView.java:2015)
       at android.view.View.dispatchSaveInstanceState(View.java:4944)
       at
android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1052)
       at
android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1052)
       at android.view.View.saveHierarchyState(View.java:4927)
       at
com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1314)
       at android.app.Activity.onSaveInstanceState(Activity.java:1055)
       at blah.blah.Blah.onSaveInstanceState(TodoEdit.java:110)
       at android.app.Activity.performSaveInstanceState(Activity.java:999)
       at
android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1255)
       at
blah.blah.BlahTest.testLoadingAndSavingState(TodoEditIntegrationTest.java:37)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:136)
       at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:126)
       at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:155)
       at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:142)
       at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:313)
       at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1508)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to