Thanks. I did give ActivityInstrumentationTestCase a try but it didn't
work. Now I gave it another try with a fresh look and it's partly
running (the test is failing, but I believe the problem is somewhere
else so if I post I'd do it as another thread).

On Sat, Jan 24, 2009 at 9:19 AM, Andrew Stadler <stad...@gmail.com> wrote:
>
> Pablo-
>
> ActivityUnitTestCase is extremely limited in its support for
> operations that require interfacing with the rest of the system,
> because the Activity is never attached to the Activity Manager or the
> rest of the runtime.  It may be possible to fix this particular case
> (so you can make this call via Instrumentation) in an update but in
> the meantime, you will probably find it easier to use
> ActivityInstrumentationTestCase - have you tried that?
>
> --Andy
>
>
> On Thu, Jan 22, 2009 at 12:28 AM, J. Pablo Fernández <pup...@pupeno.com> 
> wrote:
>>
>> Hello,
>>
>> In an ActivityUnitTestCase I'm trying to do:
>>
>>                Activity activity = startActivity(INSERT_INTENT, 
>> initialState, null);
>>                Bundle outState = new Bundle();
>>                
>> getInstrumentation().callActivityOnSaveInstanceState(activity, outState);
>>
>> But on the save state call I get this trace:
>>
>> android.util.AndroidRuntimeException: Acquiring SearchManager objects
>> only valid in Activity Contexts.
>>        at 
>> android.app.ApplicationContext.getSearchManager(ApplicationContext.java:976)
>>        at 
>> android.app.ApplicationContext.getSystemService(ApplicationContext.java:861)
>>        at 
>> android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:73)
>>        at android.app.Activity.getSystemService(Activity.java:3091)
>>        at android.app.Activity.performSaveInstanceState(Activity.java:1004)
>>        at 
>> android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1255)
>>        at 
>> com.blah.blah.SomeActivityTest.testLoadingAndSavingState(SomeActivityTest.java:90)
>>        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)
>>
>> Going through the ApplicationContext source code I've found this
>> (http://tinyurl.com/d8qsyc):
>>
>>    private SearchManager getSearchManager() {
>>        // This is only useable in Activity Contexts
>>        if (getActivityToken() == null) {
>>            throw new AndroidRuntimeException(
>>                "Acquiring SearchManager objects only valid in
>> Activity Contexts.");
>>        }
>>        synchronized (mSync) {
>>            if (mSearchManager == null) {
>>                mSearchManager = new SearchManager(getOuterContext(),
>> mMainThread.getHandler());
>>            }
>>        }
>>        return mSearchManager;
>>    }
>>
>> It seems the problem is that the activity token is not set. But here
>> I'm puzzled, I don't know where to go next. Any ideas on how to fix it
>> or workaround it are appreciated. I want to test that my application
>> is saving its state correctly.
>>
>> Thanks.
>> --
>> J. Pablo Fernández <pup...@pupeno.com> (http://pupeno.com)
>>
>> >
>>
>
> >
>



-- 
J. Pablo Fernández <pup...@pupeno.com> (http://pupeno.com)

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

Reply via email to