[Solved] SharedPreferences between activity and service

Put your problem here if it does not fit any of the other categories.

[Solved] SharedPreferences between activity and service

Postby tsucheck » Sat Mar 08, 2008 8:59 pm

Hi,

I'm running into some strange behavior and was wondering if anyone else seen it.

I have an activity that onCreate gets an SharedPreferances.Editor then I add a variable to SharedPreferences and commit. I then start my service. In the service I retrieve the same variable and printout the value, sure enough its what I set in my Activity. However if I modify this value in my service, in get the updated version of it in my Activity I do not see the updated value. Instead I see the very original value that was set in my activity onCreate.

To summorize. When I set a value in my activity I can retrieve it in my service. But when I change the value in my service it does not see that change in my activity. In both cases when I set the values I "commit".

Any ideas?

Thanks.

Tom
Last edited by tsucheck on Sat Mar 08, 2008 9:41 pm, edited 1 time in total.
tsucheck
Developer
Developer
 
Posts: 29
Joined: Sun Feb 17, 2008 2:07 am

Top

Postby krystox » Sat Mar 08, 2008 9:21 pm

Hi,

If your service is running the different process like in Remote Service. You are not gonna see the prefs changes made in another process like your Activity. Change your service to Local mode, in which they share the same process, will solve the problem.
krystox
Freshman
Freshman
 
Posts: 7
Joined: Tue Jan 22, 2008 2:39 am

Postby tsucheck » Sat Mar 08, 2008 9:30 pm

Thanks krystox. I start the service with startService. How do you start services in local or seperate process? Do you mean to use bindService which implicitly starts a service?
tsucheck
Developer
Developer
 
Posts: 29
Joined: Sun Feb 17, 2008 2:07 am

Postby krystox » Sat Mar 08, 2008 9:37 pm

In AndroidManifest.xml remove the android:process=":remote" in your service description.
krystox
Freshman
Freshman
 
Posts: 7
Joined: Tue Jan 22, 2008 2:39 am

[SOLVED]

Postby tsucheck » Sat Mar 08, 2008 9:40 pm

Thanks krystox!

That did it.
tsucheck
Developer
Developer
 
Posts: 29
Joined: Sun Feb 17, 2008 2:07 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests