Questions tagged [android-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.

539 questions
60
votes
3 answers

Does the presenter having knowledge of the Activity / Context a bad idea in the MVP pattern?

I've been playing around with the MVP pattern for a few weeks now and I've come to the point where I need context to start a service and access Shared Preferences. I've read that the purpose of MVP is to decouple the view from the logic and having…
remedy.
  • 2,032
  • 3
  • 25
  • 48
47
votes
8 answers

How to examine SharedPreferences from adb shell?

Now that we can Examining sqlite3 Databases from a Remote Shell, is it possible to examine SharedPreferences from adb shell? Since it would be much more convenient to examine and manipulate SharedPreferences from command line when debugging. Or put…
an0
  • 17,191
  • 12
  • 86
  • 136
37
votes
3 answers

PreferenceFragment - Difference between getPreferenceManager() and getPreferenceScreen()?

I've implemented my own PreferenceFragment subclass (detailed here), and want to listen for preference changes within it. PreferenceFragment provides you with two ways of doing…
XåpplI'-I0llwlg'I -
  • 21,649
  • 28
  • 102
  • 151
36
votes
9 answers

LiveData with shared preferences

I have a settings screen where I am setting some values. When I set those values it gets saved in shared preferences and these values are needed in my request to the network api call as parameters. Now I can use a listener for shared preferences in…
nick.tdr
  • 4,627
  • 4
  • 28
  • 41
28
votes
1 answer

java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

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 =…
20
votes
6 answers

setDisplayHomeAsUpEnabled() not working in PreferenceActivity

I have a SettingsActivity which extends PreferenceActivity to show settings in my app. There is a back arrow, but it is not working. Here's SettingsActivity.java file's code: public class SettingsActivity extends PreferenceActivity implements…
17
votes
4 answers

What's the difference between getDefaultSharedPreferences() and getPreferences()?

I'm currently taking the "Developing Android Apps" Udacity course. In the "Lesson 3: New Activities and Intents > Use SharedPreferences" segment, the instructor asked me to dig around the Android Developer site for how to get the user preferences…
fqf555
  • 199
  • 1
  • 1
  • 7
14
votes
3 answers

How to convert Drawable into int and vice versa in Android

I want to convert Drawable into int and then vice versa.Basically I want to save Arraylist object into sharedPrefrence. For that purpose I have Implement Gson to Srtring convertion Method. If I use here Drawable instead of int then Gson String…
M.ArslanKhan
  • 3,640
  • 8
  • 34
  • 56
13
votes
1 answer

Android preferences - what is the difference?

What is the difference, when I get preferences as: PreferenceManager.getDefaultSharedPreferences(getBaseContext()); and getPreferences(Context.MODE_PRIVATE);
LA_
  • 19,823
  • 58
  • 172
  • 308
12
votes
4 answers

PreferenceDataStore in Android O

I read this article https://medium.com/@ianhlake/hidden-gems-of-android-o-7def63136629 . This is what is written there: SharedPreferences is dead. Long live SharedPreferences. Will SharedPreferences keep working in Android O ? Do we need to…
N Sharma
  • 33,489
  • 95
  • 256
  • 444
11
votes
2 answers

Android preferences adding unwanted chars

I have a big problem with the SharedPreferences in Android. The preferences are adding unwanted chars to one of my string values once the application is closed. Actually it is a configurable escape sequence. I have a simple setup, a MainActivity…
patman
  • 2,780
  • 4
  • 30
  • 54
9
votes
1 answer

StrictMode: StrictModeDiskReadViolation when creating SharedPreference

I have a project with dagger setup with following provider method: @Module(...) abstract class AppModule { @Module companion object { ... @Provides @Singleton @JvmStatic fun provideSharedPreferences(@AppContext context:…
azizbekian
  • 60,783
  • 13
  • 169
  • 249
8
votes
1 answer

What does it mean by VM wide cookie management?

I am learning to store cookies in Android and came across several ways of implementing it. One of them being the use of CookieManager and CookieStore. As I was going through Android docs, I came across the following statement: To establish and…
7
votes
2 answers

What is the difference between Preferences and SharedPreferences in Android?

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…
7
votes
2 answers

Android project with different modules(sharedPreferences)

Does anyone know if android supports sharing the same sharedpreference across multiple Android Modules compiled in one project? i have two shared preferences and currently when i try to access some data from a shared prefence outside of the current…
Jono
  • 17,341
  • 48
  • 135
  • 217
1
2 3
35 36