does variables in shared preferences share accross applications? - android

I want to share variable between two android application so I stored it in shared preference but when I reinstalled the application that store the variable the second application didn't see the variable, what is the best way to share variable between two application and dealing with situation when one of them will be reinstalled
I used this code
SharedPreferences globals_prefs = ctx.getSharedPreferences("globals_prefs", Context.MODE_WORLD_WRITEABLE);

The SharedPreferences in one application is stored as a prefs.xml file in a separate folder dedicated for you app in the Android File System. So when you uninstall an app, this folder also is deleted, thereby, all Preferences made by your app is removed. So a better way is to use Files to store it in the sdCard.

Note: currently this class does not support use across multiple processes. This will be added later.
From android dev documents
http://developer.android.com/reference/android/content/SharedPreferences.html
File or sqlite database on public directory would do the trick when sharing data

When you uninstall an app shared preference and internal cache is wiped out, so the only way is to use external storage.

Related

How to refresh SharedPreferences after adding an xml file to its storage location

I have the following problem: Since I want to keep my shared preference data even if the .apk is uninstalled I copy its .xml file to an external location as described here: Android Backup of ENTIRE SharedPreferences file. However, after reinstalling the app and starting the application I import the .xml to the shared preferences location but it won't be found by the app at the very first time. It works after shutting the app down and restarting it again. What can I do that it already works from the beginning? It seems like to be necessary to refresh the shared preferences directory, but how can that be done within the app?
Thanks in advance
You can put files in a directory derived from Environment.getExternalStorageDirectory(). These files will persist after an uninstall. However, a user can delete those files any time they like, regardless of whether your app is installed or not.

Shared Preference Directory - genymotion

I work on a application that save data on shared preferences
when I using AVD for test my app shared preference file exist in below directory and all things is ok
/data/data/MY_PACKAGE_NAME/shared_prefs/setting.xml
But when I use Genymotion, data folder is empty in eclipse file explorer.
How could I access to shared preferences?
i find my answer here.
this problem Happens when we have not appropriate permissions

Can someone change my app's preferences?

I want to create a preference file for my app and I want to ensure that no one will be able to change the content of the file. Can It be changed not by my app?(I change my preferences file by the code, I don't allow the user to change it with the app)
When you save in shared preferences file, it cannot be changed by some other user. However, if he has a rooted phone, it is possible for him to view shared preferences file, through command-line adb root commands, but it will be read-only so he cannot change it. If he then tries to make it read-write using
chmod 666
or similar options, it might affect your shared preferences, and the working of your app depending on how your app uses those shared preferences, but this will be momentarily for that execution and again a fresh read-only preferences file will be generated by the app. So yes, in rooted phone cases, it might be possible. But for general non-rooted cases, it cannot be done.

How to change the android sharedPreferences save path?

I want to change the android sharedPreferences save path,the sharedPreferences save in /data/data/xxx.xxx.xxx/shared_prefs,i want to change path to /sdcard. how i do?
You cannot modify where shared preferences are stored. Since shared preferences are simply stored in an XML file, you are welcome to read and write XML data on external storage as you see fit.
BTW, never use /sdcard. Use Environment.getExternalStorageDirectory(). /sdcard is not the correct path for over a third of existing Android devices.

configure an android application

Guys, I need an android application that can be configured by the user. In java, we are using properties file to configure the applications. Any idea about the same in android..
Thanks in advance
I can guess you need preferences.
You can use SharedPreferences or PreferenceActivity (this article will be a good start).
If you want your files that can beaccessed from outside you should have some xml file in your resource folder or you can also sed a file along with your application and store iton external memory as andorid do not provide you feature of acessing private datas, toa ccess private datas u need content providers that will be overhead as in your case..
hence better, u bundle a xml file along with you app, which at deployment need to save a copy at sd card and once its there everytime you should check for that file..
this way user will be able to chnge the contents without even running the program, also other application will be able to access youir file
hope this helps

Categories

Resources