KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been developing an Android application which interacts with other applications installed on the device via a sharedpreference file. This file was created as MODE.WORLD_READABLE and every installed application has its own file with a common defined name and property (what changes is the value for that specific property). For example, AppA and AppB should have each one a shared file named "app_shared_file.xml" with a property "property_shared_file". From my application I want to first access this file and read that property value, and depending on that result I want to create/update mine. Nevertheless, I'm having some problems in achieving that. On the Android documentation I see that: Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values. Only one instance of the SharedPreferences object is returned to any callers for the same name , meaning they will see each other's edits as soon as they are made. After reading the other application shared preferences file, when I try to create/update mine the system instead of editing mine is using the one I have previous read. If on the contrary, I start by updating mine and read the other app later - instead of reading the other one, the one being accessed is mine. Any thoughts? The code I'm using for reading the shared pref is [where packageName is the other app pckg]: Context con = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); SharedPreferences pref = con.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_WORLD_READABLE); pref.getBoolean(SHARED_PREF_PROP, false); The code I'm using for writing in the app shared pref is: SharedPreferences prefs= getSharedPreferences(SHARED_PREF_NAME, context.MODE_WORLD_READABLE); SharedPreferences.Edi
Tags (comma-separated)
Save Edits
Cancel