Questions tagged [sharedpreferences]

SharedPreferences allows you to save and retrieve persistent key-value pairs of primitive data types in Android applications. It can be used either inside a single app or shared between multiple apps.

SharedPreferences allows you to save and retrieve persistent key-value pairs of primitive data types in Android applications. It can be used either inside a single app or shared between multiple apps.

You can learn more about SharedPreferences under the Data Storage section in the Android documentation.

7696 questions
38
votes
2 answers

How secure are SQLite and SharedPreferences files on Android?

First, a bit of my background. I have been working on large web systems for over a decade, Android is something I have been looking at for the past two months; as you can imagine, the gap is quite wide :) Looking at Android's Security and…
David Kuridža
  • 7,026
  • 5
  • 26
  • 25
38
votes
7 answers

Android SharedPreferences String Set - some items are removed after app restart

I save a string set in the shared preferences, if I read it out it's ok. I start other activities, go back and read it again, it's ok. If I close the application, and start it again, I get the set, but with only 1 item instead of 4. It happens all…
user2313423
  • 745
  • 3
  • 7
  • 12
35
votes
6 answers

Flutter One time Intro Screen?

I have an intro screen for my app, but it shows every time I open the app, I need to show that for the 1st time only. How to do that? //THIS IS THE SCREEN COMES 1ST WHEN OPENING THE APP (SPLASHSCREEN) class SplashScreen extends StatefulWidget { …
Rajesh
  • 3,562
  • 7
  • 24
  • 43
35
votes
3 answers

Android SharedPreferences , how to save a simple int variable

I am trying for the last hour to save an integer in my Android application. I read that this can be done using the SharedPreferences. However i dont understand why it seems so confusing to do so. How can i simply save an int variable ? And then when…
donparalias
  • 1,834
  • 16
  • 37
  • 60
34
votes
6 answers

Accessing SharedPreferences through static methods

I have some information stored as SharedPreferences. I need to access that information from outsite an Activity (in from a domain model class). So I created a static method in an Activity which I only use to get the shared preferences. This is…
MyName
  • 2,136
  • 5
  • 26
  • 37
33
votes
10 answers

encrypt data in SharedPreferences

Im currently developing a framework for oAuth 1 and 2 access to webservices and my question is, how do i store sensitive data like an oAuth access key in a secure way? the problem with this keys is that some platforms like twitter use a permanent…
Simon
  • 13,173
  • 14
  • 66
  • 90
31
votes
4 answers

Run a piece of code only once when an application is installed

I want to run a piece of code only once in my application and is when i run it for the first time (newly installed app). How could i do this, can anyone explain giving a piece of code. Actually, in my android project i want to create database and…
Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
30
votes
7 answers

MODE_MULTI_PROCESS for SharedPreferences isn't working

I have a SyncAdapter running on its own process separately from the main app process. I'm using a static wrapper class around my SharedPreferences that creates a static object on process load (Application's onCreate) like so: myPrefs =…
marmor
  • 27,641
  • 11
  • 107
  • 150
28
votes
5 answers

Problems using SharedPreferences on a Service (getPreferences doesn't exist on a service)

I have some shared preferences (latitude, longitude) that I want to access from a service, that is not subclassed from Activity. In particular, when I try to access getPreferences, this function doesn't exist's on a service. My code is posted…
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
28
votes
5 answers

SharedPreferences Clear/Save

Iam trying to make a checker and I want to save a value into SharedPreferences. But i'am not sure if it works This what I do to save the value is : * SharedPreferences prefs = getSharedPreferences("PREFERENCE", MODE_PRIVATE); boolean…
Tirolel
  • 928
  • 3
  • 17
  • 43
27
votes
5 answers

Delete SharedPreferences File

I am allowing the user to create multiple SharedPreferences files, but I also would like the option for them to delete these files. I know I could use internal storage, but that is not my question. My question is: "How can I delete in code or…
Andrew
  • 830
  • 3
  • 10
  • 27
27
votes
5 answers

BackUpAgentHelperClass is not getting called

I want to backup data in Android using MyBackUpAgent class which extends BackupAgentHelper. I am using SharedPreferences in order to store data. My mainactivity code is: public class MainActivity extends Activity { EditText inputtext; …
abh22ishek
  • 2,631
  • 4
  • 27
  • 47
27
votes
6 answers

SharedPreferences value is not updated

I am trying to update the values of SharedPreferences, here is my code: edit =…
Juned
  • 6,290
  • 7
  • 45
  • 93
26
votes
3 answers

Android - Is it bad practice to have multiple Shared Preferences?

I have an app making use of SharedPreferences. One just stores app version to check against update for a changelog, the other contains some layout info that clear() gets called on as the user chooses. I finally managed to get a PreferenceFragment…
ziondreamt
  • 467
  • 1
  • 4
  • 14
25
votes
1 answer

Action Bar Home Button not functional with nested PreferenceScreen

I found a workaround to actually enable the ActionBar home button on the nested PreferenceScreen... however it doesn't call OnOptionsItemSelected in my PreferenceActivity. Anyone know a way to actually use the home button on a nested…