sharedpreferences

Android: How to get the time from a TimePicker when it is typed in

左心房为你撑大大i 提交于 2019-12-17 18:09:32
问题 I've got a DialogPreference which implements a simple TimePicker.OnTimeChangedListener (see below). Setting the time by clicking the +/- buttons works great. But I don't know how to save the state of the timepicker when the user typed in the time directly into the textfield. It could be sufficient to access to the current textfield value, so I'd be able to persist it in onDialogClosed. But timePicker.getCurrentHour() won't do it. Please help... public class TimePreference extends

How can I backup SharedPreferences to SD card?

北战南征 提交于 2019-12-17 17:59:32
问题 I saw in a lot of places that it's a problem to copy the SharedPreferences file to the sd card because every manufacturer place it somewhere else. I want to backup on the sd card no matter where is the file located. Is there any way to do this? 回答1: The SharedPreferences interface contains a method called getAll() which returns a map with the key-value pairs. So instead of copying the file itself, I just serialize the map that being returned from this method and then retrieve it back

Android: Keep username in session until logout

旧巷老猫 提交于 2019-12-17 17:52:43
问题 I'm having hard time trying to figure out how to use SharedPreferences to store the username in the phone and stay in session until logout. I also need to know how at the same time its in session it will send the username out with the data the user click on within the listview. Below are the codes I am using and would like to know where and what code to put in order to acheive this. As login it will go to the menu and stay at the menu (avoid the backbutton from going back to the login screen)

Delete SharedPreferences File

半腔热情 提交于 2019-12-17 15:44:12
问题 I am allowing the user to create multiple SharedPreferences files, but I also would like the option for them to delete these files. I know I could use internal storage, but that is not my question. My question is: "How can I delete in code or manually (not just clear) a SharedPreferences file?" 回答1: If you get SharedPreferences instance via Context.getSharedPreferences("X") , then your file will be named X.xml . It will be located at /data/data/com.your.package.name/shared_prefs/X.xml . You

Flutter: Access Stored Sharedpreference value from Other Pages

ε祈祈猫儿з 提交于 2019-12-17 14:22:31
问题 I'm storring a vlaue in a page1.dart,i want to access the stored value from page2.dart or page3.dart, How can i achive this?? 回答1: Flutter shared preferences is actually implemented as an in-memory cache. The first time that you call SharedPreferences.getInstance() all the current values are read from NSUserDefaults (on iOS) and SharedPreferences (on Android) and cached in memory. This involves channels, so is async. The Future returns a singleton class that wraps this cache. Any subsequent

How to detect if changes were made in the preferences?

心不动则不痛 提交于 2019-12-17 08:48:05
问题 I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This helps... http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html Other related post: SharedPreferences.onSharedPreferenceChangeListener not being called consistently public class PreferenceClass extends PreferenceActivity { OnSharedPreferenceChangeListener listener; public void

How to detect if changes were made in the preferences?

痞子三分冷 提交于 2019-12-17 08:47:45
问题 I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This helps... http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html Other related post: SharedPreferences.onSharedPreferenceChangeListener not being called consistently public class PreferenceClass extends PreferenceActivity { OnSharedPreferenceChangeListener listener; public void

How to detect if changes were made in the preferences?

99封情书 提交于 2019-12-17 08:47:35
问题 I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This helps... http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html Other related post: SharedPreferences.onSharedPreferenceChangeListener not being called consistently public class PreferenceClass extends PreferenceActivity { OnSharedPreferenceChangeListener listener; public void

Android SharedPreferences in Fragment

删除回忆录丶 提交于 2019-12-17 08:04:16
问题 I am trying to read SharedPreferences inside Fragment. My code is what I use to get preferences in any other Activity. SharedPreferences preferences = getSharedPreferences("pref", 0); I get error Cannot make a static reference to the non-static method getSharedPreferences(String, int) from the type ContextWrapper I have tried to follow these links but with no luck Accessing SharedPreferences through static methods and Static SharedPreferences. Thank you for any solution. 回答1: The method

Shared Preferences reset data when app is force closed or device is restarted

删除回忆录丶 提交于 2019-12-17 07:41:09
问题 I'm developing an application in which I'm storing username and password in SharedPreferences . All things are working fine for me, storing as well as retrieving the values. But I discovered that when I restart the device or the app is force closed the value stored in SharedPreferences is reset. And when I again launch my app I get null values in SharedPreferences key. Here, is what I'm doing for storing the values: SharedPreferences emailLoginSP; emailLoginSP = PreferenceManager