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 <[email protected]> (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 [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
-~----------~----~----~----~------~----~------~--~---