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:
Is
MODE_PRIVATE
OK? Does that mean it's private for the application or the Activity/Service?I have a
PreferenceActivity
. How do I tell it to manage "somename" instead of the default preferences?
Thanks!
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.