LiteWait
LiteWait

Reputation: 634

Sharing preferences between an Activity and a Service

I have an .apk that has a Service and an Activity that I want to share preferences. I guess I use getSharedPreferences("somename", MODE_PRIVATE) to do that. A couple of questions though:

  1. Is MODE_PRIVATE OK? Does that mean it's private for the application or the Activity/Service?

  2. I have a PreferenceActivity. How do I tell it to manage "somename" instead of the default preferences?

Thanks!

Upvotes: 3

Views: 2932

Answers (1)

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43108

MODE_PRIVATE : File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID). So, MODE_PRIVATE is ok.

To share preferences between activity and service all you need is to use application context to access(read and write) the preferences, not activity or service context.

Upvotes: 4

Related Questions