sharedpreferences

How can I display values from EditText user input?

◇◆丶佛笑我妖孽 提交于 2019-12-25 03:38:31
问题 I have a SharedPreferences that saves EditText input from one activity and displays the String value in another activity. When I enter an input into the EditText fields and press (a button I created) "Save" (which commits the EditText to editor), the file is stored successfully. However, the display activity (which displays the stored String values in SharedPreferences) doesn't display the values. I am guessing it is because it is the onCreate, so the screen is "created" when it runs. How can

How to edit shared preferences in an activity other than the one it is created in?

微笑、不失礼 提交于 2019-12-25 03:34:49
问题 I have created some shared preference in an activity and I want to modify it in a broadcast reciever...How can I do that??? Please help... I have tried looking but couldn't get the answer 回答1: You should be able to do: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor edit = prefs.edit(); using the context passed into the BroadcastReceiver. 来源: https://stackoverflow.com/questions/7853564/how-to-edit-shared-preferences-in-an-activity

Save Application Wide Boolean in SharedPreference

雨燕双飞 提交于 2019-12-25 03:18:05
问题 I know that this is a common question asked, and I have spent all afternoon trying different solutions that don't seem to work. I am trying to store a boolean receiveNotifications in SharedPreferences but when I send a notification it still comes through. When I check whether the boolean is set in the activity I set it in, it says that the value is what it should be, but when I call this in my Firebase MessagingService it still allows the notification to come through. This is my first time

Adding values from a arrayList to shared Preference

♀尐吖头ヾ 提交于 2019-12-25 02:18:47
问题 Is it possible for me to store and retrieve my ArrayList values using shared preference. Can anyone suggest me with an example. 回答1: It looks like the closest the SharedPreferences can do is save a Set of String s. If that doesn't suit you should probably look at the alternatives for persisting data. 回答2: You can refer to this : http://androidcodemonkey.blogspot.com/2011/07/store-and-get-object-in-android-shared.html (Thanks to Greg Zimmers that give this tutorial). The idea is you

Saving audio content Uri in sharedpreference to play later

雨燕双飞 提交于 2019-12-25 02:09:16
问题 I am trying to design an Alarm app where Audio is played when the device is shaken. I am selecting the Audio from file system using "ACTION_GET_CONTENT" in Intent with ActivityForResult . I am able to fetch the content uri , saving it in SharedPreference and playing it with MediaPlayer on a different Activity passing the URI in Intent . But, once I close my app and reopen it and try to play the Audio from the URI in SharedPrederence , the Audio is not played. What can be done so that I can

sharedpreferences putting an array

让人想犯罪 __ 提交于 2019-12-25 01:53:43
问题 how can I use this code in order to add an array and retrieve it later? can I use a simple for loop? SharedPreferences settings = getSharedPreferences("isChk", 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("keys",ArrayValue[i] ); editor.commit(); and how can I then retrieve them and store each element in an array variable can I use this? for( int i=0; i<myArr.size(); i++){ keys[i] = settings.getBoolean("isChk", false); isChkb.add(keys[i]); } 回答1: To store an array

Remove some SharedPreferences

若如初见. 提交于 2019-12-25 01:38:45
问题 I am making a simple slashing game and I am saving stuffs like gold in SharedPreferences . How to remove it from SharedPreferences but still be able to call the value of the gold,like Temple run 2 game. 回答1: To remove specific values: SharedPreferences.Editor.remove() followed by a commit() To remove them all SharedPreferences.Editor.clear() followed by a commit() If you don't care about the return value and you're using this from your application's main thread, consider using apply() instead

I used sharePrereference to save the string in textView, afyer turn off app and open again, it doesnt work

旧巷老猫 提交于 2019-12-25 00:29:45
问题 As title, i want to get the new string after i edit the textView, after i edit it and turn on the app again, The textview were still empty, Could some one help me what did i miss in my code, Thank you in advance for any assistance that can be provided here. Here is my code below: public class MainActivity extends ActionBarActivity { //private SharedPreferences saveUserName; private AutoCompleteTextView editText1, editText2, editText3, editText4, editText5, editText6; private ImageButton

SharedPreferences.Editor not being updated after initial commit

大城市里の小女人 提交于 2019-12-25 00:05:38
问题 I'ma a bit confused here. I'm trying to change the value of an EditTextPreference, but it is not updated in the view. (This is in a PreferenceActivity) Here is my code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.modify_instrument_preferences); // Set default values SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor =

libGDX: Using preferences for highscore

亡梦爱人 提交于 2019-12-25 00:04:53
问题 I know I have asked this question so similar before but I get there no more answer ... I would like, as soon as I lost in my game, my HighScore displayed. Here is the code: protected Preferences HighScore () { if (score > highscore) { prefs.putInteger("highscore", score); this.highscore = prefs.getInteger("highscore", 0); prefs.flush(); } return prefs; } But if I run my application, only this error is displayed: Exception in thread "LWJGL Application" java.lang.NullPointerException at de