android-sharedpreferences

SharedPreferences replacement of data

旧巷老猫 提交于 2019-12-20 07:56:20
问题 I have application that gives me some string whenever I press the button and then save this value using sharedpreferences. However, I would like to limit this saving function, so it will save only the last three received strings. The structure is of the following: String A String B String C Next time when i click my button it will record the value into String A, while move the old String A to String B and old value of String B to String C, as well as, delete the old value of String C

SharedPreferences being reset after force close

☆樱花仙子☆ 提交于 2019-12-18 09:01:11
问题 I have been able to successfully implement Shared Preferences into my application but I have ran into a problem with the data being reset/deleted if I kill the application through a task manager. I am using a static method for saving, that way I only need the method once and can call it everywhere within my app. protected static synchronized void save(Context cntx){ SharedPreferences preferences2 = cntx.getSharedPreferences("BluRealms", 0); SharedPreferences.Editor editor = preferences2.edit(

java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

时间秒杀一切 提交于 2019-12-17 19:08:05
问题 The exception only occurs in Android 7.0 Nougat (emulator) devices. java.lang.SecurityException: MODE_WORLD_READABLE no longer supported My code: public void SessionMaintainence(Context context) { this.context = context; preferences = context.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_READABLE); editor = preferences.edit(); editor.commit(); } LogCat: > E/AndroidRuntime: FATAL EXCEPTION: main > Process: burpp.av.feedback, PID: 2796 > java.lang.RuntimeException: Unable to create

Save String (Cookie) to SharedPrefs caused NullPointerException

柔情痞子 提交于 2019-12-13 23:09:36
问题 I´ve made a class with helps me to handle the Authentication (save Cookie to SharedPrefs). public class Authentication extends Application { String PREFS_NAME = "UserData"; String DEFAULT = ""; Context context; public static SharedPreferences sharedPreferences; public static SharedPreferences.Editor editor; public static String token; public Authentication(Activity context) { this.context = context; sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); editor =

Spinner with SharedPreferences

风格不统一 提交于 2019-12-13 04:12:33
问题 Good evening. I'm trying to save the choice the user makes in Spinner in SharedPreferences, when he clicks OK, but I'm not getting it, can anyone help me? Then I want to redeem the choice made when it opens the application again and puts it in a textView. Follow my code. mShowDialog = (Button) findViewById(R.id.btnEscolhaCidade); mShowDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder mBuilder = new AlertDialog.Builder

Remove a specific item from a Set in Sharedpreferences

冷暖自知 提交于 2019-12-13 02:01:56
问题 I have a Set of Strings in my sharedPrefs. I would like to remove a specific item in the list <set name="items"> <string>217372223</string> <string>222015066</string> <string>217771052</string> <string>220431322</string> So I would like to just remove say, 217372223 but keep the rest? 回答1: You can use the remove(String key) method of SharedPreferences.Editor SharedPreferences sharedPreferences = context.getSharedPreferences("items", Context.MODE_PRIVATE); sharedPreferences.edit().remove

SharedPreferences - OnSharedPreferenceChangeListener

纵然是瞬间 提交于 2019-12-12 18:26:52
问题 I googled this and found a few answers which I find confusing since I am a beginner. I am trying to implement the OnSharedPreferenceChangeListener() to my SharedPreferences to make something happen with the change. My code so far is: final SharedPreferences rates_storage = this.getApplicationContext().getSharedPreferences("uk.chiraggalaiya.test", 0); final SharedPreferences.Editor rates_storage_editor = rates_storage.edit(); Button btn = (Button) findViewById(R.id.button); btn

How to show search view recent search history

﹥>﹥吖頭↗ 提交于 2019-12-12 17:16:26
问题 I tried to using following ways but unable to show recent search history Create "history" to SearchView on ActionBar Implementing SearchView in action bar kindly help how to create and show recent search in serachview searchable xml 回答1: These are step i am using Searchable xml file <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_label" android:hint="@string/search_hint" android:searchSuggestAuthority=

An Image Downloaded From Parse Stay On Screen Even After You Exit And Reopen App?

不羁的心 提交于 2019-12-12 04:02:31
问题 I have an app that downloads an image from Parse.com and displays that image in an Image View The problem is that whenever I exit the app (with the back button) and return the image is gone. How can I make the image stay? (For example: when you update your profile pic on Twitter and leave the app and return your profile pic will still be displayed) Any help would be greatly appreciated this is very important. MainActivity: public class MainActivity extends Activity { Button button; private

SharedPreference values not retrieved in different Activities

…衆ロ難τιáo~ 提交于 2019-12-11 18:27:06
问题 I have three Activities .When my application opens the first time ActivityOne is opened and I am saving a value in preference and using Intent I go to ActivityThree and replace one Fragment in layout. This is code for saving value in ActivityOne SharedPreferences prefs; SharedPreferences.Editor edit; prefs=MainActivity.this.getSharedPreferences("myPrefs",MODE_PRIVATE); edit=prefs.edit(); @Override public void onResponse(JSONObject response) { try { saveToken = response.getString("token");