Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I share a SharedPreferences file across two different android apps?
    primarykey
    data
    text
    <p>I've been struggling with this for a while. Basically, I want to have two applications (which will always be installed together) share preferences, with one of them being just a service which runs in the background and needs to use the preferences (should own the preferences but only <em>really</em> needs to read them) and the other app being a front-end UI app which needs to be able to write to the preferences file owned by the other app. The service will be doing things in the background (which may be determined by the preferences) and the UI will allow the user to edit the preferences and view some information from the service. However, they will be different packages/apps.</p> <p>I tried following <a href="http://thedevelopersinfo.com/2009/11/25/getting-sharedpreferences-from-other-application-in-android/">this tutorial</a> which gave me a pretty good idea of how to have preferences in one app which can be read by another. Essentially, I create a new context through <code>myContext = createPackageContext("com.example.package",Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);</code> and then call <code>myContext.getSharedPreferences("pref_name", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);</code> However, I can't write to the preferences successfully from the outside app - (SharedPreferences.Editor).commit() returns false and I get a warning in logcat about being unable to edit pref_name.xml.bak. </p> <p>How can I successfully set up my applications so both of them can read and write to the same preferences file (which is stored in the data folder of one of them)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload