Wednesday, May 15, 2013

[android-developers] Re: Sharing SharedPreferences from two different processes

Michael,
Sorry but I don't understand your example.  You are specifying MODE_PRIVATE which is what I am doing...

SharedPreferences myMemory = getSharedPreferences("myMemory", MODE_PRIVATE);

Are you saying that if I specify "| 0x4" (don't know what that means) that it will be the same as specifying MODE_MULTI_PROCESS?
btw, I'm targeting 2.33 gingerbread.
Gary

On Monday, May 13, 2013 11:59:32 PM UTC-7, Michael Schollmeyer wrote:
I do something like this:

prefs = context.getSharedPreferences(context.getPackageName() + "_preferences", Context.MODE_PRIVATE | 0x4); // Context.MODE_MULTI_PROCESS

Which also compiles in earlier API levels. The additional flag does no harm in pre-level-11 runtimes. 

Also notice that OnSharedPreferenceChangeListener will not trigger across processes.


On Tuesday, May 14, 2013 1:29:37 AM UTC+2, Gary Blakely wrote:
My app originally had an activity and a service running in the same process. When I first wrote it I specified sharedPreferences with MODE_PRIVATE. The app has grown, and for reasons beyond the scope of this post, I now need to run my service in a different process.

I found I can do this by specifying a name starting with a colon in the android:process statement in my manifest file.

However now my activity and my service are no longer reading the same sharedPreferences. Researching this problem I see many reccommendations to use MODE_MULTI_PROCESS. But I cannot figure out how to spedify it.

SharedPreferences myMemory = getSharedPreferences("myMemory", MODE_MULTI_PROCESS);

This does not work because Eclipse can't find MODE_MULTI_PROCESS like it can find MODE_PRIVATE or MODE_WORLD_READABLE.  I don't know where the ENUM for MODE_MULTI_PROCESS is.

So, how can I specify MODE_MULTI_PROCESS ??
thanks, Gary

--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment