Android - How to get only my own SharedPreferences - android

My app can backup and restore all my data, including the shared preference values. However, when I get all my shared preferences, I also get two with the names "drt" and "drt_ts". I've discovered these are from Admob.
Is there any way for me to iterate through the preferences and get ONLY the one ones my own app has created? There doesn't seem to be any concept of owner or creator.

If you want to have your own SharedPreferences, that is separate from the Default one for your app you should consider using SharedPreferences.getSharedPreferences(String name, int mode). The BackupHandler has support for multiple SharedPreferences files.
If you want to have AdMob save their preferences somewhere else then that is a different question, maybe it is possible, check with the documentation for AdMob?
http://developer.android.com/reference/android/content/Context.html#getSharedPreferences%28java.lang.String,%20int%29

Related

Does Shared preferences get shared across user

I am having some question, kindly help me out, following are my questions?
Does shared preferences data get shared across users?
Also can we have same widget IDs in two different users?
I am having a widget which any user can use. I am getting some
conflicts when a guest user or a any new user is switched to. Specifically, my widget is resizeable and in order to save its state so that it can be inflated accordingly on phone restart or some refresh events. These are working perfectly for the Admin User but it behaves abnormally when a guest is added or if the user is switched.
Yes shared preferences data get shared across users if we define CONTEXT MODE while creating SahredPreference for more detail you can read here for detail, and here. For widget id i think we can give same id in different users but here (i am not sure) also should be concept of Mode.

What happens if I change my Preference settings of SharedPreference

what if I have a Code like this:
SharedPreferences prefs=getSharedPreferences("myPrefs",0);
And now I am so dumb and set it to (lets say the first release of my app had the above code....now several months later I release it with the code change below on the store)
SharedPreferences prefs=getSharedPreferences("myPrefs",1);
So I change the acces of it from 0(private) to 1(world readable) or 2 (world writeable)
Are there now two Preferences? So I have to sets of Preferences with different Key-Value pairs and different read/write visibilities in them but all have the same name/key?!
Thank you
since AFAIK android allocate a linux user to each app to acheive some kind of sandbox environment, my guess is that you only change the underline file linux premissions from private (access to the app's user only) to readable by all other programs, if they can access it they would be able to read it.

I need multiple sets of settings. Is this possible with Android or should I roll my own settings implementation?

I'm working on a monitoring system that can accommodate many Sites. A Site is defined by an ID and Password, as well as some boolean options.
It's fairly easy to manage one site with the settings. I can use PreferenceManager to get the Default Shared Preferences for a Context, and each setting is identified by a string Key. But is it possible to have multiple sets of settings? E.g. for each Site to have its own set of settings?
If not, should I bypass the PreferencesManager and store settings for each site in a Sqlite database?
You can use Properties and create activity manually

SharedPreferences for general app preferences and user session identificators

I'm using SharedPreferences to save two kinds of preference information.
1) General app preferences like results per page, sessionTime, etc. which are accessible only once you're logged in.
2) A session identifier like the users name and surname. One can see the name on every activity/page so as to know the the session is ok.
Is it ok for me to use sharedPreferences with 2 separate string identifiers. One for general settings and another for session info and manage the usage of these setting through my global application class or is my approach totally wrong?
By design Android does not differ between application/user preferences. Don't bother creating 2 different preference files, just use PreferenceManager.getDefaultSharedPreferences(yourContext) everywhere

SharedPreferences on android

I have a problem with SharedPreferences and my PreferenceActivity. I need that my application can difference between differentes preferences and users, so every user has his own preferences. I thought in use SharedPreferences sending to it the user ID to get the correct options. The problem is that I dont know how to do for my PreferenceActivity use that specific options. Currently, It is using the context options, so when I restart my application, it loads the last options modifieds...
How can I configure my preferenceActivities to store his changes in the sharedpreferences that I want? And for the load?
Thanks!
It's unusual to support the concept of 'users' on Android - most apps assume a phone has a single user.
That said, you can create custom SharedPreferences like this
SharedPreferences userprefs = getSharedPreferences(username,MODE_WORLD_READABLE);
For your PreferenceActivity, in onCreate you do this
getPreferenceManager().setSharedPreferencesName(username);
Hope that helps...
This might be a bit late, but you can also check out Swarm's Cloud Data, which provides a per-user SharedPreferences system, stored in the cloud (so if the user switches devices, their preferences persist on the new device).

Categories

Resources