mardi 29 novembre 2016

test suite not overwrite DefaultSharedPreferences

I am using the SettingsActivity created by AndroidStudio (extends AppCompatPreferenceActivity, which extends PreferenceActivity). My preference values are getting stored in the DefaultSharedPreferences (pkg-name_preferences.xml).

I'd like to be able to specify a different name for the DefaultSharedPreference file when the test suite is running. This would prevent the test suite from over-writing any preference values I may have set during normal use of the app.

Is it possible to do this? (Just to be clear: I am able to detect if the test suite is running, but I don't know how to specify a name for the DefaultSharedPreferences.)

I found some old posts that suggest:

PreferenceManager prefMngr = getPreferenceManager();
prefMngr.setSharedPreferencesName("my_name");

getPreferenceManager() was deprecated in API 11, and if I try to use it anyway it returns null.

Or maybe there is some other way to achieve my objective (test suite not over-writing app's preference values)?

Aucun commentaire:

Enregistrer un commentaire