sharedpreferences

Android SharedPreferences not changing

好久不见. 提交于 2019-12-24 10:58:20
问题 So I am learning about SharedPreferences within Android. I thought I would quickly try and mock up something simple. When the user selects a particular option from a list of options (3 options in this case) - the layout file will change accordingly. However, it always assumes the default value supplied, hence never changes the layout when another option is selected - so when another option is selected, it is recorded fine, but the layout doesn't change, this leads me to believe that there is

How to save DateFormat with SharedPreferences in Flutter?

强颜欢笑 提交于 2019-12-24 10:57:53
问题 I tried to count the number of pressed button for each hours. To do this When I pressed the button, I save the current time in a variable to have a reference of the hours of the pressed button, if I press a second time the button, I want to compare the current time with the previous time saved to know if the hours has changed. If there is a different time I reset the counter to 0, else I increase the counter. Like this I can know how much I pressed the button for each hours. There may be a

SharedPreferences between arbitrary applications

半城伤御伤魂 提交于 2019-12-24 10:26:25
问题 Picture, if you will: Applications A, B, C and D. All need to share some small amount of data between them but there is no guarantee that any of them will be installed. That is, you may have B and D only. Or A and C only, etc. Can SharedPreferences be used in this case? I understand that I can use createPackageContext to have A-D all use the package space of A, if A is like a master-app that is always installed, but what if I don't know which of these will be installed? createPackageContext

store Array in sharedpreferences

家住魔仙堡 提交于 2019-12-24 10:03:36
问题 I have an Array with integer values. It will grow over time. It will have approximately up to 50 values. I want to store the array persistent and thus I thought about storing it in SharedPreferences . I know that no complex types can be stored in it, but I also heard about to serialise the Array and then store it in SharedPreferences . Can someone give me a hint or even better sample code how to do that? 回答1: Not very efficient way, but will get the job done: SharedPreferences prefs = ...;

update preferences values after changing them programatically

微笑、不失礼 提交于 2019-12-24 08:49:23
问题 i've got a simple PreferenceActivity. in my activity im using the values stored in those keys. through getDefaultSharedPreferences and getBoolean("somekey") if i now change the preference associated with "somekey", everything works fine and the getBoolean returns the right value. but if i set the value "somekey" to another value programatically, via Preferences.Editor the settings view doesn't update to the new value! like this: pref_edit.putBoolean("somekey", true); pref_edit.commit(); if

Save an array of booleans using Shared preference

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:34:31
问题 I have a long list of booleans which i want to save In my app using shared preference, so that i can save the state of a number of checkboxes. i have tried a few approaches now, and am now so sick of the same code, that im even willing to ask for help. I would post my code, but there is so much greentext and redundant information that i dotn think its worth it. But if it helps. import java.util.HashMap; import java.util.Map.Entry; import android.content.Context; import android.content

CheckBoxPreference - onSharedPreferenceChanged method not getting called

删除回忆录丶 提交于 2019-12-24 06:49:09
问题 I have a couple of CheckBoxPreferences set up, my preference class extends PreferenceActivity and implements OnSharedPreferenceChangeListener This is what I'm using to respond to people checking/unchecking the CheckBoxPreferences : public void onSharedPreferenceChanged(SharedPreferences P, String K) { if (K.equals(CheckBoxPref_KEY_HERE)) { MyClass.BooleanVariable = P.getBoolean("CheckBoxPref_KEY_HERE", true); } } As far as I can tell, the onSharedPreferenceChanged method above is never even

Ringtone Preference defaults to Silent even though defaultValue set

随声附和 提交于 2019-12-24 05:57:58
问题 I'm using preferences.xml to allow selection of a ringtone (among other preferences). Here's the code <RingtonePreference android:key="shuttle_tone" android:ringtoneType="notification" android:showDefault="false" android:showSilent="true" android:defaultValue="content://settings/system/notification_sound" android:summary="Select the tone that signals the start of the next shuttle" android:title="Shuttle Tone" /> ... a bunch of other preferences The Preferences activity is initiated in the

shared preferences for storing a single score

喜你入骨 提交于 2019-12-24 03:51:19
问题 I am developing this quiz game. at the end of the game I show the user a detailed total score. What I want to develop here is a using sharedpreferences to store the value, be able to retrieve it using other activity showing the user's total score. I am only interested in storing one score for the quiz (initially). The reason I want to implement this is that in the future I will apply this for other quiz modes and show the total score for all quizzes in one activity called highscores. below is

Android - App keeps crashing with error - I think it has to do with Preference Fragments

老子叫甜甜 提交于 2019-12-24 02:58:05
问题 I keep getting an error that has to do with the preferences and I know it has depreciated so I looked here for help http://developer.android.com/reference/android/preference/PreferenceFragment.html and I did exactly as it says on the bottom part... Here is the error: 12-04 00:39:37.553: E/AndroidRuntime(1164): FATAL EXCEPTION: main 12-04 00:39:37.553: E/AndroidRuntime(1164): Process: com.proteintracker, PID: 1164 12-04 00:39:37.553: E/AndroidRuntime(1164): java.lang.RuntimeException: Unable