android-sharedpreferences

Shared Preferences loading multiple values

瘦欲@ 提交于 2020-01-17 05:45:20
问题 I currently am saving usernames and passwords in different shared preferences files. I want to load every value saved in the XML file, not just the first. How would this be written? 回答1: One way you could do it is the following: //if you are running the code inside from an Activity Context context = this; SharedPreferences userSharedPrefs = context.getSharedPreferences("USER_NAME_PREFS", MODE_PRIVATE); SharedPreferences pwdSharedPrefs = context.getSharedPreferences("PWD_PREFS", MODE_PRIVATE);

What is the difference between Preferences and SharedPreferences in Android?

五迷三道 提交于 2020-01-14 08:58:27
问题 What is the difference between java.util.prefs.Preferences and android.content.SharedPreferences ? Looks like they are for similar things - you can put and get a value by a key in both of them, but Preferences looks like something more difficult and belongs more to the OS than to an app. 回答1: Preferences is a core java class link1 java.util.prefs.Preferences : This class allows applications to store and retrieve user and system preference and configuration data. This data is stored

How to save online data with SharedPreference in Android

喜你入骨 提交于 2020-01-11 14:42:29
问题 I want to show 3 fragments in my Activity and load data from json in any fragments ! I need to show website data into Recyclerview with OkHTTP v3 library. I want to show this data for offline, I mean, if user turn off data/wifi show this datas for offline . but i do not want use SQLite Database ! For this idea i use SharedPreference for save data and when disable network show show to offline data from this Preference . I write below codes, but when disable network not show me datas the

How to save online data with SharedPreference in Android

独自空忆成欢 提交于 2020-01-11 14:42:17
问题 I want to show 3 fragments in my Activity and load data from json in any fragments ! I need to show website data into Recyclerview with OkHTTP v3 library. I want to show this data for offline, I mean, if user turn off data/wifi show this datas for offline . but i do not want use SQLite Database ! For this idea i use SharedPreference for save data and when disable network show show to offline data from this Preference . I write below codes, but when disable network not show me datas the

Set default values for the SharedPreferences for the whole aplication

吃可爱长大的小学妹 提交于 2020-01-07 09:56:22
问题 I have the application with coding key, that should be visible from all parts of the application. It has to have a default value and an ability to be changed from one of the activities. How can I set this default value? 回答1: To save default value you have Two options . 1. SharedPreference 2. Database. Try with SharedPreference Create Helper class. public class SharedPreferencesHelper { private static final String TAG = "SharedPreferencesHelper"; Context context; SharedPreferences

How to save RadioButton status with SharedPreference?

两盒软妹~` 提交于 2019-12-25 09:26:05
问题 This is the app view: and here is my activity code: public class Quiz extends AppCompatActivity { public static int point; public static int i = 0; RadioGroup radioGroup; public static int totalPoint =0; int arrValues[]={0,0,0,0}; int iPosition=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); i = 0; final RadioButton radioButton1 =(RadioButton) findViewById(R.id.number_1); final RadioButton

Error while accessing shared preferences of Android App's first run

六月ゝ 毕业季﹏ 提交于 2019-12-25 07:47:19
问题 Whenever I run my Android app for the first time after installation and access the shared preferences, I get this system error - remove failed: ENOENT (No such file or directory) : /data/user/0/com.example.ap/shared_prefs/com.google.android.gms.appid.xml.bak I am not able to figure out what this error means. Any help will be appreciated. Thanks Code to access shared preferences - String setOrNot; SharedPreferences sharedPref = getSharedPreferences("LastFetchTimeFile",MODE_PRIVATE); if

Shared preferences from other activity to be call with button

隐身守侯 提交于 2019-12-25 07:24:44
问题 I'm a beginner trying to understand sharedpreferences . Everything is going smoothly as my program of shared preferences run as I want it to be . My inputs are in activity 1 and using shared preferences, I call them back in activity 2. But how can I call the inputs from activity 1 to activity 3 using shared preferences by just using a button from activity 2? 回答1: Store sharedpreference to Constant class and use static variables than set and get values from that class anytime you want. Setting

Pick .mp3 file from sdcard in preferencescreen

泪湿孤枕 提交于 2019-12-25 07:14:05
问题 How i can pick mp3 file from sdcard in android preferenceScreen menu.. here is my preferenceScreen: <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/app_setting"> <Preference android:title="@string/ChooseRingtone" android:key="sdPref" /> </PreferenceCategory> </PreferenceScreen> here my SettingActivity: public class SettingsActivity extends AppCompatPreferenceActivity{ @Override public void onCreate(Bundle

How to: Keep track of Progress on questionnaire

匆匆过客 提交于 2019-12-25 00:02:34
问题 Good day all, I am working on a practice app that involves fragments, keeping track of data, and SharedPreferences , Here is the scenario, I have a questionnaire-like app, it will ask the user 15 questions but for the sake of this example i'm going to say five(5) and use random questions with yes and no buttons as options.It will look something like this: |Question 1: Are you a citizen?| yes/no |Question 2: Are you human?| yes/no |Question 3: Do you sleep a lot?| yes/no |Question 4: Do you