sharedpreferences

Unresolved reference: getPreferences

不问归期 提交于 2019-12-24 01:01:37
问题 I am trying to store a boolean value which is changed every time a button is clicked. I want to do this using shared preferences, however I keep running into this error: Unresolved reference: getPreferences This is my code: btnStyle.setOnClickListener() { styleHasChanged = !styleHasChanged; if(styleHasChanged == true){ btnStyle.setText("true") }else{ btnStyle.setText("false") } // AppUtil.saveConfig(activity, config) // EventBus.getDefault().post(ReloadDataEvent()) var sharedPref :

Explain perf difference in accessing SharedPreferences on different Android devices

别来无恙 提交于 2019-12-23 20:26:58
问题 I am trying to debug extreme performance differences for users of my Android app. I have traced it to extreme differences in DB write time and SharedPreferences read and write time. Here are 7 performance tests I wrote to test the speed of SharedPreferences: private void testEditor1() { SharedPreferences settings = this.getSharedPreferences(Constants.PrefsName, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("testEditor1", true); editor.commit(); } private void

SharedPreferences not Save if the application is re-open

早过忘川 提交于 2019-12-23 20:04:44
问题 My sharedpreferences does not save if i re-open my game the data that i saved before with SharedPreferences are not load, setting on my current activity is back to normal again or default this is the image of my button in menu.class this is the following code of my menu.class @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

Can't get onSharedPreferenceChanged() to work

拈花ヽ惹草 提交于 2019-12-23 19:24:51
问题 I wanna display a dialog when the user selects a specific item from a ListPreference in my preferenceActivity. But, I cannot get the onSharedPreferenceChanged() to work. I've put a Toast in the beginning of the method, and it does not show, so the method doesn't even run through, why is this? Here's my code: (Thanks) public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Toast.makeText(Preferences.this, "prefs Changed", Toast.LENGTH_SHORT) .show(); if (key

Are the shared preferences associated with the App deleted when the app is removed?

萝らか妹 提交于 2019-12-23 15:11:16
问题 Are SharedPreferences value for an App retained even after it is removed? If not, I would like to retain the SharedPreferences even after the app is uninstalled/removed. Is there a way? Edit: I am reluctant to store the settings on the SD Card. Is there a way I can store them in the phone memory itself? 回答1: SharedPreferences are deleted when an app is uninstalled, but you can use the BackupManager to perform a backup into the cloud - Reto Meier has a good blog post for getting you started.

Store ArrayList<CustomClass> into SharedPreferences

醉酒当歌 提交于 2019-12-23 11:46:00
问题 I have an ArrayList of custom class Task public class Task { String name,desc; Date date; Context context; public Task(String name, String desc, Date date, Context context) { this.name = name; this.desc = desc; this.date = date; this.context = context; } } I want to save it in SharedPreferences.. I read that can be done by converting it to Set.. But I don't know how to do this.. Is there a way to do this? Or any other way to store data rather than SharedPreferences? Thanks :) EDIT: String s =

Why cannot save INT to SharedPreferences?

回眸只為那壹抹淺笑 提交于 2019-12-23 10:08:07
问题 I have a strange problem. I have never had it before. When I try to save int value to my SharedPreference and then restore in other Activity. Value is always 0 even if I save there other value (for example: 1); private String Number; private String Profile; and then saving values (in this case "1") to SharedPreferences in first Activity: SharedPreferences a = FirstActivity.this.getSharedPreferences("a", MODE_PRIVATE); SharedPreferences.Editor prefsEditorProfiles = a.edit();

What's the point of having a default value in sharedPref.getString?

烈酒焚心 提交于 2019-12-23 09:57:54
问题 I'm accessing my Android apps SharedPreferences via private val sharedPref = PreferenceManager.getDefaultSharedPreferences(context)` and then attempting to get data from it using val lat: String = sharedPref.getString("MyKey", "Default") But this line gives me an error reading "Type mismatch. Required String, found String?" According to the documentation the second parameter in the getString method says "Value to return if this preference does not exist. This value may be null. " So what's

Store cookie in sharedpreferences

别等时光非礼了梦想. 提交于 2019-12-23 09:38:21
问题 I've been pulling my hair trying to figure this out: I'm making an HttpsURLConnection and using java.net.cookiemanager to manage my cookies (there's no way of using android.webkit.cookiemanager to HttpUrlConnection/HttpsUrlConnection as I have understood?). I need to save my longtime cookie to later connections. Sadly I can't use http://loopj.com/android-async-http/ and it's PersistentCookieStore because I need to allow an untrusted certificate (using http://abhinavasblog.blogspot.se/2011/07

How to set multiple default values in a MultiSelectListPreference?

◇◆丶佛笑我妖孽 提交于 2019-12-23 06:55:02
问题 I have preference.xml like this <MultiSelectListPreference android:key="store_select" android:title="@string/setting_store_title" android:summary="@string/setting_store_summary" android:dialogTitle="@string/setting_store_dialog_title" android:entries="@array/store_names" android:entryValues="@array/stores" android:defaultValue="@array/stores" /> with my two arrays: <string-array name="stores"> <item>1</item> <item>2</item> <item>3</item> <item>4</item> <item>5</item> </string-array> <string