sharedpreferences

Can Shared Preferences be private?

怎甘沉沦 提交于 2019-12-30 05:41:11
问题 From the name alone, I am guessing that Shared Preferences are... shared among apps? That is, even if my app defines and creates them, any app on android can access them. Is this correct? (If this isn't correct, then why does the Data Storage Dev Guide emphasize Internal Storage as "Store private data"?) If this is correct, can I modify this default behavior so that a preference is only visible from the app in which I define and create it? If so, how do I do that? 回答1: If i'm correct you can

Can Shared Preferences be private?

孤人 提交于 2019-12-30 05:41:06
问题 From the name alone, I am guessing that Shared Preferences are... shared among apps? That is, even if my app defines and creates them, any app on android can access them. Is this correct? (If this isn't correct, then why does the Data Storage Dev Guide emphasize Internal Storage as "Store private data"?) If this is correct, can I modify this default behavior so that a preference is only visible from the app in which I define and create it? If so, how do I do that? 回答1: If i'm correct you can

Android SharedPreferences update does not work

我怕爱的太早我们不能终老 提交于 2019-12-29 08:42:07
问题 I know, this issue has been dealt with in many threads, but I cannot figure out this one. So I set a shared preference like this: SharedPreferences prefs = MainActivity.this.getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putStringSet(spinnerName, myValueSet ); editor.apply(); I read the preferences like this: SharedPreferences prefs = MainActivity.this.getPreferences(MODE_PRIVATE); Set<String> spinnerValuesSet = null; spinnerValuesSet = prefs.getStringSet

SharedPreferences not being updated

南楼画角 提交于 2019-12-29 07:34:06
问题 I am having an odd issue in which the SharedPreferences are not being updated upon returning to an app. Here's the scenario: I have two projects that use the same shared preferences. Project1 and Project2. They are separate but related apps. They are signed with the same key and use sharedUserId to share information. Project1 opens Project2. Project2 retrieves the SharedPreferences file and writes to it via this method: Context prefsContext = c.createPackageContext(packageNameOfProject1,

SharedPreferences application context vs activity context

笑着哭i 提交于 2019-12-28 11:49:10
问题 I am using several SharedPreferences to store data in my app. Some preferences are used in a lot of activites. I know that the SharedPreferences are internally backed by a map for fast read-access and written to sdcard when settings are changed. I wonder which way is better if a sharedpreference is accessed by a lot of activies: Instantiate it in every activity using the activity context. Instantiate it in every activity, but using the application context. Put it in e.g. the Application class

save the state when back button is pressed

徘徊边缘 提交于 2019-12-28 04:08:07
问题 I am developing an android app. If I press a back button the state of my application should be saved .What should i use to save the state ..am confused with all of these onPause() , onResume() , or onRestoresavedInstance() ??? which of these should i use to save the state of my application?? For eg when i press exit button my entire app should exit i have used finish() ? public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); s1=

How to listen for preference changes within a PreferenceFragment?

半城伤御伤魂 提交于 2019-12-27 18:22:10
问题 As described here, I am subclassing PreferenceFragment and displaying it inside an Activity. That document explains how to listen for preference changes here, but only if you subclass PreferenceActivity. Since I'm not doing that, how do I listen for preference changes? I've tried implementing OnSharedPreferenceChangeListener in my PreferenceFragment but it does not seem to work ( onSharedPreferenceChanged never seems to get called). This is my code so far: SettingsActivity.java public class

How to listen for preference changes within a PreferenceFragment?

让人想犯罪 __ 提交于 2019-12-27 18:22:09
问题 As described here, I am subclassing PreferenceFragment and displaying it inside an Activity. That document explains how to listen for preference changes here, but only if you subclass PreferenceActivity. Since I'm not doing that, how do I listen for preference changes? I've tried implementing OnSharedPreferenceChangeListener in my PreferenceFragment but it does not seem to work ( onSharedPreferenceChanged never seems to get called). This is my code so far: SettingsActivity.java public class

Data on main activity doesn't save / load properly with SharedPreferences

ⅰ亾dé卋堺 提交于 2019-12-26 03:55:01
问题 If you look through each picture, from left to right, you'll notice on the last picture on the right, the points for Quiz One goes to 0... this is my problem This is a quiz app that i'm working on, with Android Studio... I am trying to use SharedPreferences, using putInt and getInt methods to put the value of points scored for each quiz into variables, stored under a String name, then part of onCreate is to getInt using the String name referenced in the putInt m ethods... main activity should

Data on main activity doesn't save / load properly with SharedPreferences

百般思念 提交于 2019-12-26 03:54:32
问题 If you look through each picture, from left to right, you'll notice on the last picture on the right, the points for Quiz One goes to 0... this is my problem This is a quiz app that i'm working on, with Android Studio... I am trying to use SharedPreferences, using putInt and getInt methods to put the value of points scored for each quiz into variables, stored under a String name, then part of onCreate is to getInt using the String name referenced in the putInt m ethods... main activity should