FAQ Database Discussion Community


How to store repeat share preference when edit display name in profile [closed]

java,android,sharedpreferences
I want to store shared preference again when user change display name in profile now, data in database has change but i don't know to change shared preference help me please. code: private static final String PREFERENCE_KEY = "pref_user"; private static final String DISPLAY_KEY = "user_display_name"; SharedPreferences sh_pref; SharedPreferences.Editor sh_edit;...

Save state button sharedpreferences Android

java,android,button,sharedpreferences
i've got a floatingbutoon (it's a button shortly), and when i click on it it starts a service and the button change icon. I tried in this way: mFab = (FloatingActionButton)findViewById(R.id.fabbutton); mFab.setDrawable(getResources().getDrawable(R.drawable.ic_play)); mFab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (RunService.isRunning) { RunService.stopRun(MainActivity.this); mFab.setDrawable(getResources().getDrawable(R.drawable.ic_play)); SharedPreferences.Editor editor =...

Trying to compare scores

android,if-statement,sharedpreferences
I am trying to compare 2 scores that I have made oldScore and best_score(both in Main_Screen). I think the problem is that the ints are not saving properly. There are no errors but if the best_Score is lower than the old_score it still changes it in the textview even though...

Preference Manager not getting value from user preferences

android,sharedpreferences,preferences
I'm making an app where whenever you go to an activity, it plays a sound file. I made a preference in which you can change the sound file it plays. Here's the code for the Preference activity: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <ListPreference android:title="Sound" android:summary="Pick the sound!" android:key="soundChoice" android:defaultValue="a" android:entries="@array/soundList"...

Get SharedPreferenes from another activity android

android,android-activity,sharedpreferences
I am trying to get the SharedPreferenes that I have saved in two different activities into my SMS activity. They are both saved as Strings. For the phone number, it is saved as a string and is just directly inside of the onActivityResult (because it is getting the phone number...

Multiple SharedPreferences in an android app

android,sharedpreferences
SharedPreferences pref = getSharedPreferences("user1", Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putString("firstName", firstnameString); editor.commit(); SharedPreferences pref = getSharedPreferences("user2", Context.MODE_PRIVATE); ... I am trying to create multiple sharedpreferences using the above code and trying to access all the sharedpreference names i.e user1,user2 etc using the code below. But i am getting a NULLPointerException...

Why SharedPreferences access time increases when Internet available? - Android

android,sharedpreferences
Here is what I am trying to do: In onCreate, I fetch data from sharedpreferences and display on list (I am using async task for this). This is working offline, no network required. So What is happening: Internet On- Fetch string from sharedpreferences in about 1 sec. Internet Off (Switched...

How to compare Int value that is saved into shared preference

android,sharedpreferences
i m trying to create Level Review and show level rating after completed beside the level image. my code is ready and showing rating after level completion i m saving score value into Shared Preference and checking for value Here is code // adding value to cookies from First Activity...

Contacts storage in Shared Preferences

android,sharedpreferences,multiautocompletetextview
I am Building an app where a Dialog box pops up when a button is clicked in an activity and the Dialog Box contain a MultiAutoCompleteTextview to select contacts in the form of contactname%number,contactname1%number,contactname2%number... so now i am stuck at a place where i have to store the individual contacts...

Android Settings : How to use SharedPreferences in a SettingsFragment?

android,sharedpreferences,settings,android-preferences
I am using my own SharedPreferences in a normal Activity with a custom layout with two checkboxes and seekbars. Now I want to make a proper SettingsActivity/SettingsFragment with these settings. Is there a way to use my custom SharedPreference instead of the PreferenceManager and the default preference file? My own...

SharedPreferences in fragment boolean value not updating

android,android-fragments,sharedpreferences
So in my MainActivity i am using SharedPreferences when checking boolean values doing like this. public boolean uptadevalues(boolean updatedvalue) { SharedPreferences preferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (mPremiumVQuery) { Log.d(TAG, "Called uptadevalues mPremiumVQuery"); editor.putBoolean(mPremiumVString, true); editor.apply(); } else { editor.putBoolean(mPremiumVString, false); editor.apply(); } Log.d(TAG, "Called uptadevalues "); return...

Increment shared preference key after adding value

android,key,sharedpreferences,value
In my app, the user can add a name and an age for multiple people. Most likely it will only be around 2 or 3. I want to store these in shared preferences. I set a counter to keep track of how many people have been stored as well as...

Android Studio: Using a String in Stored in Shared Preferences in Card View Layout

java,android,xml,sharedpreferences
I would like to use a string value stored in Shared Preferences in a Card View. I know most likely I can not add it to the XML layout directly. If that is the case, what is the java that adds this string to the existing TextView in the XML...

Couldn't create directory for SharedPrefrences

android,sharedpreferences,samsung-mobile
I am getting the following error only on Samsung device. Went through this but it doesn't really provide a solution. Couldn't create directory for SharedPreferences file shared_prefs/log_files.xml To be specific : This is how I have declared SharedPreferences in onCreate settings = getSharedPreferences("preferences", MODE_PRIVATE); How to tackle this error ?...

Using SharedPreferences for ColorPicker Android?

android,sharedpreferences,color-picker
In my app I've ColorPicker that is AmbilWarna color picker. When I select the desired color from ColorPicker, it works like charm. But when I close and restart the Activity, the color changes to default. Hence I'm trying to use SharedPreferences to make it work, I've tried SharedPreferences in EVERY...

Share info between two processes - what's the safest way?

android,process,sharedpreferences,android-broadcast
I have an app with two processes - the MainActivity and a background Service. I need the same information in both, and this info comes from my server (a JSON response). I was loading this JSON from both processes, but as this JSON may get bigger it's pretty inefficient to...

Setting SharedPreference within Fragments as Tabs

android-fragments,tabs,sharedpreferences
I'm having problems with what I thought was a simple use of SharedPreferences! Aim: I've a ActionBar/Tab application with a MainActivity and 4 Tabs as swipe Fragments. I want the App to remember the last user selected Tab, so that on the next start of the App, it defaults to...

Why doesn't my “SharedPreferences” work?

java,android,sharedpreferences
The Problem is, that the Text field which is in "Wizard2Activity" just shows "nothing" and not what the user has typed in the "EditText" in "Wizard1". Wizard1.java: package com.CENSORED.CENSORED; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; public...

PreferenceFragment not saving values - with test case and screenshot

android,android-fragments,sharedpreferences,android-preferences,android-settings
I have prepared a simple test case at GitHub for my question and have a feeling, that only few lines of code are missing to make it working. In an Android app I have 1 activity (MainActivity.java) and 2 fragments (MainFragment.java and PrefFragment.java) - and when I change values in...

Save Spinner with SharedPreferences in fragment (OnItemSelectedListener)

android,fragment,sharedpreferences,spinner,onitemselectedlistener
I am new to Android programming and at the moment I am trying to make some spinners with four array elements (string-array), and then save the current state with shared preferences. I've already done a lot of research, but most of the solutions only work for activities, and I am...

Storing Values in SharedPreferences

android,sharedpreferences
I am trying to store values for username and password fields using SharedPreferences and use those values to populate EditText fields. The fields are not being populated and I'm not sure what I'm doing wrong. Here is my login() method that is called when the login button is pressed. In...

Unable to resume activity - SharedPreferences

android,sharedpreferences,onresume
I'm trying to implement a "first-launch" method that will open a specific activity the first time the user opens the app. I have a SharedPreferences called prefs: public class MainActivity extends ActionBarActivity { SharedPreferences prefs = null; public static final String DEFAULT = "N/A"; @Override protected void onCreate(Bundle savedInstanceState) {...

Can't get screen to show settings options

java,android,android-studio,sharedpreferences,preferences
EDIT Added MyActivity.java (i.e., main activity) at bottom EDIT2 Added lines to MyActivity.java (this solved the problem) I have preferences set up but have no way to access them. No matter what style I pick in xml and no matter what virtual device or style I pick in Android Studio...

shared preferences from new boston tutorial button not working on click

android,sharedpreferences
i have searched on SO but not found solution to my problem. i m new to android and following new boston tutorial. and in sharedpreferences activity buttons are not working on click.showing nothing no exception nothing my code is : package com.ss; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.SharedPreferences;...

How to store an integer in an activity for calculation

java,android,android-studio,sharedpreferences,calculator
I'm currently creating an application that adds together values to give an overall total, like so. oldValue + newValue = textView1... MainActivity, this is where the overall value is to be stored in textView1 String calorie = getIntent().getStringExtra("calorie"); TextView textView1 = (TextView)findViewById(R.id.textView1); String strOldValue = textView1.getText().toString(); Integer oldValue; try{ oldValue=...

In-app Billing Version 3 API SharedPreferences storage alternative

android,sharedpreferences,in-app-billing
I'm going through the implementation of Android's In-app Billing Version 3 API, and came across the following warning in Android's sample code: /* * WARNING: on a real application, we recommend you save data in a secure way to * prevent tampering. For simplicity in this sample, we simply store...

android: use stored value and adding new value to it

android,sharedpreferences
I have this code to store a value in my Activity: tv_addzekr.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub nowzekr=nowzekr+1; tv_nowzekr.setText(nowzekr+":the score"); savecurrentzekr(nowzekr); } }); Then i save nowzekr value with this method : public void savecurrentzekr (int id){ SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);...

Trying to retrieve data from a Shared Preferences

android,android-intent,sharedpreferences
I have tried to retrieve data from Shared Preferences and tried to intent it over to my main activity where I want it to display the score the user got. There are no errors, it just doesn't save the best_score_number_tv or doesn't correctly send it over. I hope there isn't...

Make a POST call every 10 seconds for an infinite time?

android,post,service,broadcastreceiver,sharedpreferences
How can I make a certain function execute after every 10 seconds for an infinite time? What I have done till now: I am getting the location values of the user from the App and storing them on the server. I am using a service, so that, the code keeps...

shared preferences for storing a single score

android,sharedpreferences
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...

java.util.ArrayList cannot be cast to

java,android,json,sharedpreferences
I'm new in android and testing my skills in different test applications. Now I'm trying to get data from Json url and create from Json's object favorite list. Gradle is finished without any problems, but every time when my app starts, it crashes with next error: Attempt to invoke interface...

how to save hashmap of objects to shared preferences

android,hashmap,sharedpreferences
I have a hashmap of objects.I want to save that to shared preferences and get it. How can I do this?

Android - save value of member field in Fragment class

java,android,android-fragments,sharedpreferences,android-lifecycle
I'm trying to do something using a boolean in a Fragment class each time the Fragment is displayed. Example My app launches, opens the FirstFragment and the boolean for the first time is always true, then I have an if clause that checks its value: if (FirstTime) { FirstTime =...

Best way to save a arraylist

java,android,arraylist,sharedpreferences,android-adapter
This question has been answered before, but the solutions doesn't seem to work for me. I would like to know what the best way is to save an ArrayList. I generate an ArrayList with all the installed applications on the phone. This list is shown in a ListView where the...

OnSharedPreferenceChangeListener callback is never executed

android,sharedpreferences,android-preferences
I've my main activity that starts a new activity (SearchResultsActivity). I also have a settings menu. I want my SearchResultsActivity to be notified every time there is a new/edited setting from the settings menu. I'm implementing the OnSharedPreferenceChangeListener the interface on SearchResultsActivity and registering itself to listen to any modification...

Android how to set default value of EditTextPreference from SharedPreference?

java,android,sharedpreferences,edittextpreference
This time in the same project I'm facing a slightly challenging issue where in settings.xml file in the res/xml folder: <EditTextPreference android:key="weight" android:title="@string/update_user_weight" android:persistent="true" android:dialogTitle="@string/update_user_weight" android:dialogMessage="@string/update_user_weight_message" android:defaultValue="" /> <EditTextPreference android:key="age" android:title="@string/update_user_age" android:persistent="true" android:dialogTitle="@string/update_user_age"...

App crashing when saving to shared preferences

java,android,sharedpreferences,onresume,onpause
I am trying to save to shared preferences. I want to be able to load from shared preferences but when I save and or load at the moment my app crashes. I also want to be able to have my handler/runnable resume when my app starts up. How can I...

setText to a saved preference

java,android,sharedpreferences,android-textview
I have saved a highscore to shared preferences, i would like to display the high score on the main menu and have it stay there even if you close the app and reopen it. i have got it to work so that it changes the textview to the highscore when...

android sharedpreferences in arraylist crashes at getItemCount()

java,android,sharedpreferences
I have this code to retrieve and save items from arraylist with sharedpreferences. But if I start my activity it gives an error: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference at com.sapps.tools.dedykapp.DayRecAdapter2.getItemCount(DayRecAdapter2.java:22) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1843) at android.view.View.measure(View.java:17448) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5465) at...

using shared preferences to store arraylist, null object returned

java,android,sharedpreferences
I have an ArrayList listwriter which I populate using this AsyncTask. class LoadAllGamesWhenNull extends AsyncTask<String, String, String> { private String id; private String stake; private String user; private String returns; private String teams; private String status; // *//** // * Before starting background thread Show Progress Dialog // *//* @Override...

How can I authenticate to my server with the Login credentials in android?

java,android,sharedpreferences,httpurlconnection,androidhttpclient
I'm very new to Android and since I'm a self learner I've been stuck with the following problem. I have a simple code in MainActivity as login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String sapCode = String.valueOf(sapcode.getText()); String userName = String.valueOf(username.getText()); String pwd = String.valueOf(password.getText()); if (sapCode.equals("017343") &&...

Android Shared Preferences Not Comitting

java,android,android-activity,sharedpreferences
I have a switch i am toggling in the app. When i close the app i want the last toggle state to save. When the app opens it will set the toggle state to the last saved state. I am using SharedPreferences to do this. For some reason my preferences...

Save new value with getSharedPreferences

android,sharedpreferences,record
I'm trying to save a new value (the number of clicks of a button) whenever the "new score" is bigger than oldscore. With a TextView I display the number of clicks while the user is tapping the button and when the time is finished I'd like to diplay the score...

Json Object Store SharedPrefrences?

android,json,sharedpreferences
Hello Here I want to Json Object in SharedPrefrences. I dont know it is the best way or not to store json object. Here i want to store Json Object and whenver need call its Json object and fatch detail to store and remove detail. here is my json format...

Store Value in SharedPreference across Activities

java,android,sharedpreferences
I am new in Android, and got a task to develop a small project to submit in my college, i have tried my best but now i need some help Let me tell you first, what i am trying to do ? I have two Activities, MainActivity and AccountActivity In...

SharedPreferences wont save value

android,sharedpreferences
final SharedPreferences sp = getSharedPreferences("birthday", 0); final SharedPreferences sp2 = getSharedPreferences("name", 0); save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences.Editor editor = sp.edit(); editor.putString("birthday", birthday.getText().toString()); editor.apply(); SharedPreferences.Editor editor2 = sp2.edit(); editor2.putString("name", name.getText().toString()); editor2.apply(); Toast.makeText(SettingsActivity.this, "Changes saved.",...

Load strings from sharedpreferences in EditText (two classes)

java,android,sharedpreferences
I have two different activity's. First one only showed to the user first time - to store phonenumber inside sharedprefs. I think the problem is my load from prefs method but just in case I will leave everything here to make it more relevant to future users. It looks like...

Accessing Sharedpreference throws android.res.content.Resources$NotFoundException

android,sharedpreferences
I have 2 activities in the project namely Main_Activity and Settings_Activity. Tried adding a new SettinsActivity from the android studio but deleted it and added a blank activity and named it Settings_Activity Have the following code in the OnCreate() of Settings_Activity sharedpreferences = getSharedPreferences("MyPref",Context.MODE_PRIVATE); try { pollTime = sharedpreferences.getInt("pollTime", 16);...

Clear Shared Preferences

java,android,sharedpreferences
I am trying to make it possible that you can save a high score and I also need the user to be able to reset/delete their high score. the TOAST works but the data doesn't get deleted. public static final String PREFS_NAME = "MyPrefsFile"; static SharedPreferences settings; static SharedPreferences.Editor editor;...

Android SharedPreference Ghost Number?

android,google-maps-api-3,sharedpreferences
I am losing my mind, I am using shared preference to create google maps markers, and it is getting coordinates from a 2130 line long text document but something is really off, here is the coordinates it is getting around line 1982 06-16 23:23:10.072 22228-22228/com.emiliogaines.fuelfinder D/X:﹕ 12.0434 990 06-16 23:23:10.072...

Recover Android SharedPreferences string

android,sharedpreferences
I'm using SharedPreferences to save a JSON string between sessions. A bug in my app made me overwrite the string with the empty String. Is there any way I can recover the string that was previously saved? Assume full access to the phone (ADB / root)...

Custom NumberPickerPreference - how to set the NumberPicker value?

android,sharedpreferences,android-preferences,android-dialog,numberpicker
I have prepared a simple test case for my problem at GitHub. I have extended a DialogPreference to a custom NumberPickerPreference - and it works well: displays a NumberPicker in a dialog and saves integer value when the dialog is closed. My problem is that the saved integer value is...

What is the best way to store string? SharedPreferences Set Collection or Files?

android,sharedpreferences
I have to store some data (string) in my Android app and I'm a dilemma. What is better solution ? Use Set Collection and keep it at SharedPreferences or I should save data to File and when I need it I have to read data from file and put it...

One can use getDefaultSharedPreferences and getSharedPreferences(nome,mode) in the same app? [duplicate]

android,sharedpreferences
This question already has an answer here: Difference between getDefaultSharedPreferences and getSharedPreferences 2 answers I'm maintaining an app that uses Shared Preferences. Normal settings are got from getDefaultSharedPreferences. I would like to store another set of preferentes (user session info, completely unrelated with the other settings), using getSharedPreferences. If...

NullPointerException When Starting PreferenceActivity

java,android,sharedpreferences,preferenceactivity,preferencefragment
SOLUTION In my arrays.xml file, the entry arrays were <string-array/> and the value arrays were <integer-array/>. My solution was to make the integer arrays string arrays. I'm trying to create a settings activity for my app, and I'm running into a lot of problems. I keep getting a NullReferenceException...

store multiple radio groups status android

android,database,sqlite,sharedpreferences
I am working on an app which have multiple Radio Groups. I want to save their checked status and restore it on next restart. So which is be the most efficient way to do that?...

Android can shared preferences be used for login purposes

android,sharedpreferences
I have android connected to a MySQL database, the user would login via email and password which is hashed. Each user has a unique ID number. When they successfully login I can transfer their Unique ID to a Shared Preference in private mode to keep track of users. Would something...

How to Secure Android Shared Preferences?

android,security,encryption,sharedpreferences
The common location where SharedPreferences are stored in Android apps is: /data/data/<package name>/shared_prefs/<filename.xml> User with root privileges can navigate to this location and can change its values.Need of protecting it is of much importance. In how many ways we can encrypt whole shared_pref's xml file? We all know that we...

OnSharedPreferenceChangeListener callback is not called across applications

android,sharedpreferences,shared-memory
We have two apps with same sharedUserId and same signature. So one application can write to others' SharedPreferences without any problem (tested). But the problem is that when App A writes something to App B's shared preferences, OnSharedPreferencesChangedListener's in App B is not get called. Both apps were running during...

Android run setup activity on first run only

android,android-activity,sharedpreferences,if-this-then-that
I am working on my first android app and i have a spinner on my main activity and when the user runs the app there after the landing screen or activity will be a different one based (not main). I am storing the selection from the spinner in a shared...

Can I write to Android SharedPreference for a different package?

java,android,sharedpreferences
I've written a game which I intend to upload to the marketplace as a free demo, and I intend to offer a full version for a buck. I'd like to make the download for the full version just a simple unlocker which writes a value to the SharedPreferences for the...

Android Splash activity not redirecting after first time setup

android,sharedpreferences,splash
I have a settings activity i want to show on first time setup only. Then i have a loading splash screen which redirects after 5 seconds. However when ive saved my settings activity, it goes to the splash page, but the splash page just gets stuck and doesnt redirect. On...

why sharedpreference commit method doesn't work in my overrided method?

android,sharedpreferences,android-preferences,preferenceactivity
i have a splashscreen activity in my app that checks to find out app first run and show user interface language selecting dialog in first run then try to store it in preferences but my code doesn't work. i want to save this in a key that exist in my...

Why making call doesn't work in android?

android,android-intent,android-activity,sharedpreferences
In my application, after clicking the button it should be able to call the corresponding number (which was given by the user). But the problem is when I dial, it says unfortunately the project has stopped.Now I am running the app in emulator, and I know that without network it...

How to save Activity Class as a variable to use it later in android

java,android,android-activity,sharedpreferences,android-gcm
i'd like to know how can i store a class as a variable. for example i'd like to store which activity to open-up when push notification is clicked, for that i created a method which accepts a class with activity extension final Class<? extends Activity> ActivityToOpen what i want is...

Clear Android Context at sign out

java,android,sharedpreferences
I am using Context in order to store user information, so that when she starts the app it will automatically retrieve the username from the context like this: final SharedPreferences prefs = getGcmPreferences(context); String userId = prefs.getString(PROPERTY_USER_ID, ""); I want to avoid retrieving this data when the user has clicked...

Should I put getDefaultSharedPreferences in application class

android,sharedpreferences
As far as I know the getDefaultSharedPreferences is loading all the preference file into memory. In my app I have many classes where I pass the context and use getDefaultSharedPreferences. During the execution these classes load so many times, then as a result getDefaultSharedPreferences is called allot. My question is:...

What I missing when tried to retrieve data from Shared Preferences

java,android,list,arraylist,sharedpreferences
Hey guyz check it out what I am missing here cause of I am not able to fetch all my data from Shared Preferences. I am making such an tasklist application in which I am saving my data(means mytask) with a certain key and storing it in the shared Preferences...

How to display Strings from ArrayList in TextView

java,android,sharedpreferences,android-textview
I need to display current values in TextView (after removing String). I'm adding String when button is On and I need to remove it, when it's Off ( I don't know if I do it well), next I need to display Strings in TextView without deleted String. I need to...

Nothing happens on pressing Menu Item

android,android-intent,android-fragments,sharedpreferences
I am trying to build an app following a tutorial. I have a "Refresh" button that's supposed to populate a ListView (through and ArrayAdaptor)with an array of data from an API call but when I press the "Refresh" button. The button is supposed to run updateWeather() method to load the...

Delete Shared Preferences in android

android,sharedpreferences
This is how i add shared preferences ct = sp.getInt("count", 0); if (ct > 0) { for (int i = 0; i <= ct; i++) { list.add(sp.getString("Value[" + i + "]", "")); } } adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); Listtt.setAdapter(adp); btnad.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {...

controlling options in an activity using a switch and displaying summary whether on/off

java,android,android-activity,sharedpreferences
I want to add an option to my preference activity similar to what is seen in chrome "home page"," save passwords " options (android app). This from my understanding launches an activity that holds a switch which controls sub options. This furthermore gives a summary indicating whether on/off. My question...

How to get integers saved into SharedPreferences [duplicate]

java,android,android-studio,sharedpreferences
This question already has an answer here: How to use SharedPreferences in Android to store, fetch and edit values 16 answers I have made a food calculator, which calculates calories (from food types) and weight (based on user input using EditText) and displays these in a TextView. How would...

Update Navigation Drawer content Value get Activity is not recognized

android,android-fragments,sharedpreferences,navigation-drawer,recyclerview
I have Navigation drawer using recyclerview with some static text. I wish to update level value at end of the static text from SharedPreferences which holds a integer value. I'm using the recyclerview for my navigaton Drawer. NavigationAdapter.java @Override public void onBindViewHolder(NavDrawerAdapter.ViewHolder viewHolder, final int i) { Drawable drawable =...

Reading from SharedPreferences vs. keeping an instance of the object

android,performance,sharedpreferences
THE SCENARIO I have a class that makes use of a request list set by the user. The request list is stored in SharedPreferences. The dilemma I'm facing is to whether to keep an instance of the request list or to read from SharedPreferences every time the request list is...

Save theme using sharedpreference

java,android,sharedpreferences
I'm trying to save my theme by using sharedpreference, so I used this code: My SettingsActivity: public class SettingsActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ThemeUtils.onActivityCreateSetTheme(this); setContentView(R.layout.settings); findViewById(R.id.blackbutton).setOnClickListener(this); findViewById(R.id.bluebutton).setOnClickListener(this); findViewById(R.id.pinkbutton).setOnClickListener(this); } public void...

Is sharedPreference cleared when an android app is reinstalled?

android,sqlite,sharedpreferences,android-sqlite,android-install-apk
When we run an app during development on a device is sharedPreference cleared when app is reinstalled ?

Android reading and writing values in array or list without overwriting previous values

android,arrays,database,sharedpreferences
Am just wondering if there is a way to save data into a text file without being overwritten. Currently i am using sharedpreferences and it overwrites the data which is okay but coinciding with this, i want somewhere where i can keep record of the value before being overwritten in...

SharedPreferences on a Button

android,sharedpreferences
I am trying to retrieve the editText value and the button color using shared preferences. For the editText, it works very well but the problem is in saving and loading the color of the button. Note that I want to save the current color of the button by onWriteClick method...

null pointer exception on SharedPreferences

android,nullpointerexception,sharedpreferences
The first time users open my app, SharedPreferences might not be created. So I want to check if SharedPreferences has a value or not, and if it has no value (ie SharedPreferences has not been created) then create it and set its value. Here is my code: public static final...

SharedPreferences getString always returns default value

android,sharedpreferences
Here is my code: public void saveValue(String value, String forKey) { SharedPreferences.Editor editor = getSharedPreferences().edit(); editor.putString(value, forKey); editor.commit(); SharedPreferences p = getSharedPreferences(); System.out.println("JUST SET TO SharedPreferences" + p.getString(forKey, "")); } in Logcat: JUST SET TO SharedPreferences But when app stops on the breakpoint I see that values are actually stored...

Android editting text file and saving strings to sharedpreferences

android,arrays,string,sharedpreferences,text-files
Ive managed to implement this into my code and get it to work, however my values are coming like this: 10.020.0, how can i put a space between 10.0 and 20.0 so it comes 10.0 20.0 Also if someone could help me figure out an alternative way to save this...

Shared Preferences saving an int?

android,sharedpreferences
I saw this on stack Need to save a high score for an Android game This is what it told me //setting preferences SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE); Editor editor = prefs.edit(); editor.putInt("key", score); editor.commit(); //getting preferences SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE); int score = prefs.getInt("key", 0); //0 is the...

Can we delete SharedPreferences when closing the app

java,android,sharedpreferences
I searched in google. i can find an answer for clearing the shared preference but i need to clear the shared preferences when app getting closed. is this possible pls help. code clear shared preference public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = preferences.edit(); editor.putString("UserName",...

EditTextPreference with false persistent does not call onSharedPreferenceChanged

android,sharedpreferences,android-preferences
I've this EditTextPreference <EditTextPreference android:title="@string/settings_server" android:summary="@string/server_name_message" android:persistent="false" android:key="SERVER_NAME" /> But with persistent="false" it does not call onSharedPreferenceChanged method. How can I detect this event keeping android:persistent="false"...

Converting ArrayList to String to store in Shared Preferences

java,android,string,arraylist,sharedpreferences
i have ArrayList with multiple value. i want to convert this ArrayList into String to save in sharedPreferences, then I want to retrieve the String and convert it back to ArrayList Please tell how to do that? (or any other idea to store and retrieve ArrayList)...

Loading listview using SharedPreferences throwing OutofMemoryError

android,listview,android-listview,sharedpreferences
I am using edittext and button in mainactivity, onclicking I want to add the text to listview which it does properly. I am also saving it using sharedpreferences,so that when I go back to mainactivity or restart app ,it automatically loads listview,but on clicking button ,I get OutOfMemoryerror at this...

Get value from shared preference in remoteview

android,sharedpreferences,remoteview
I am having a widget and i want to set some value from settings activity. I have saved values to shared pref using this code: MainActivity.editor.putInt("selected_theme", 1); MainActivity.editor.commit(); And in remoteview class i have done like this in onUpdate method: MainActivity.prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE ); MainActivity.editor = MainActivity.prefs.edit(); int saved_value...

How to convert List to ArrayList and vise-versa?

java,android,list,arraylist,sharedpreferences
I have a CustomClass which is Bean/Model/Pojo and it is used to save Custom Obejcts from Json. I want to save the ArrayList of my CustomClass in SharedPreference and retrieve it back in a special scenario. I found a way of storing it in SharedPreference here! The correct answer is...

Google Sign-in “check first time login” and “Logout” issues in android application

android,sharedpreferences,logout,google-plus-signin
I am making an android application, when the user installs the application, he/she needs to sign-in with google account, after successful logged-in , he/she will be redirected to the dashboard page. If he/she closes application and opens it again and if they are already logged in then dashboard activity should...

Android no set default values

android,sharedpreferences
I followed all the instructions for setting default preference values step by step but does not work. 1º I set the default values: <PreferenceCategory android:title="@string/settings_game" > <ListPreference android:defaultValue="1.5" android:entries="@array/intervale_count" android:entryValues="@array/intervale_count_values" android:key="interval" android:title="@string/interval" /> <ListPreference android:defaultValue="@string/mode_normal" android:entries="@array/mode_game"...

Android array to Sharedpreferences with Gson

java,android,arrays,sharedpreferences,flexjson
I need to create an array of the last 5 call dates. I know that I have to save the date on the array but I don't know how to reorder the other records to keep this last call date the 1st record. And always maintain only 5 records The...

Android - When to use Shared Preferences and when to use SQLite

java,android,android-studio,sharedpreferences,android-sqlite
I have created a food calories app, where users can enter foods and weights and my app will calculate the total calories. I have also created a 'Save' button, which when pressed will take the calories just calculated and display it on the Main Activity. When the 'Save' button is...

SharedPreferences deleted when the app is killed

android,sharedpreferences,google-cloud-messaging
I have a Service which can receive notifications (with Google Cloud Messaging) and notify the user. In that very service, I also store the message sent by Cloud Messaging by using SharedPreferences. I gather those messages in a HashSet, and neither that HashSet nor any of its elements are supposed...

How to put Like function under an image and save the “Liked” status?

java,android,android-studio,imageview,sharedpreferences
I'm trying to figure out how to put a "Like function" to a few local stored images and remember the app that the user liked those images. Let me explain: I want the user to be able to press "Like" under the image he likes. This means the "Liked" status...

Why SharedPreferences use the context?

android,android-intent,sharedpreferences,android-context
I try to use SharedPreferences, but I don't understand why we need the context. If I create a SharedPreferences with the context of my main activity, can I get something with another context? For example with an intentService class Thanks...

SharedPreferences not working as expected in Android

android,sharedpreferences
I have a help activity in my app and I want it to only launch in first run. I have tried this: In on create of Help Activity: SharedPreferences settings = getSharedPreferences("prefs", 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("firstRun", true); editor.commit(); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); In onResume of...

How to change PIN using SharedPreferences in Android?

android,sharedpreferences
I created an App which has a 4 digit PIN Number to Login. I saved that in a String varaible like String defaultPin="1234";. I gave an option in OptionsMenu to change PIN. If we click Change PIN it will prompt a Dialog with three EditText boxes to get Old PIN,...

Android - SharedPreference converting to Double

android,string,double,sharedpreferences
Basically i have a valued saved into shared preference as a string. I am retrieving the value saved, and am trying to use it in a calculation. How can i convert this so that it is seen as a double instead of a string? Once the value is retrieved after...