Data Sharing Strategy Among Activities and Remote Service
<p>I was wondering, is there any good data sharing strategy, among Activities, and a spawned remote service running in separate process. So far, I had tried 3 methods, none of them work.</p>

<h2>Use <code>Application</code></h2>

<p>I first thought, there will be only an <code>Application</code>, shared among 2 different processes, as their are origin from a single application. </p>

<p>But that is not the case. I realize, before a main <code>Activity</code> is created, an <code>Application</code> will be created. When I spawn a remote service, another new <code>Application</code> instance will be created too.</p>

<h2>Use <code>Preferences</code></h2>

<p>My first thought is that, this is a file based. So, whenever I write a value to <code>Preferences</code> through <code>sharedPreferences.edit().putString(key, value).commit()</code>, the change will be committed to file. Another process should be able to read the latest changes. </p>

<p>But this is not the case. My guess is that, this is because in my service, I acquire the <code>Preferences</code> instance only once during service start up through <code>PreferenceManager.getDefaultSharedPreferences(application)</code>. It only read value from file during 1st time. Subsequent call <code>getString</code> will be read from memory.</p>

<h2>Use Global Static Variables</h2>

<p>Not workable as <code>Activity</code> and remote <code>Service</code> are in 2 different processes. They are having 2 different memory spaces.</p>

<p>Any better strategy I can try out?</p>
