title: Managing SharedPreferences in both PreferenceActivity and Service within same app
body: <p>I'm building an app with a <em>PreferenceActivity</em> and a <em>Service</em> (running in its own remote process due to <em>android:process=":remote"</em> flag) and both need to access programmatically the <em>SharedPreferences</em>. At present time I'm getting a <em>SharedPreference</em> object with the following code that uses the <em>getSharedPreferences</em> method defined in both <em>Service</em> and <em>PreferenceActivity</em> classes:</p>
  
  <pre><code>SharedPreferences sharedPrefs = getSharedPreferences("com.mypackage_preferences", MODE_PRIVATE, MODE_MULTI_PROCESS)
  </code></pre>
  
  <p>Is this the same as the following?</p>
  
  <pre><code>SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences()
  </code></pre>
  
  <p><strong>1)</strong> In the second one I can not specify flags, or is there a way to specify them? </p>
  
  <p><strong>2)</strong> Do I really need to specify MODE_MULTI_PROCESS since I'm accessing/modifying the shared preferences from both <em>Service</em> and <em>PreferenceActivity</em>? I think that most of the time you have a <em>PreferenceActivity</em> that modifies the properties and another <em>Activity</em> that reads/modifies them, so is MODE_MULTI_PROCESS needed almost always or is it only needed when there are multiple and possibly concurrent accesses to the <em>SharedPreferences</em> (as in my case, with the background service that can be active while you're editing preferences in <em>PreferenceActivity</em>)</p>
  
  <p><strong>3)</strong> The documentation of <a href="http://developer.android.com/reference/android/content/Context.html#MODE_MULTI_PROCESS%20MODE_MULTI_PROCESS" rel="nofollow">MODE_MULTI_PROCESS</a> says <em>This behavior is sometimes desired in cases where the application has multiple processes, all writing to the same SharedPreferences file</em>, does this mean that my <em>Service</em> and my <em>PreferenceActivity</em> can point different preference files? How do you change the preference file name in a <em>PreferenceActivity</em>?</p>
  
  <p><strong>4)</strong> Shared preferences are named in this way because they are shared among all the components (activities, services etc) of your application, right? Non shared preferences (i.e. the ones you can get with <em>getPreferences()</em> in you activity) are local to the component that creates them but are being saved in the same *com.mypackage_preferences* file? This could answer to my doubts in point <strong>3)</strong></p>