kanmani
kanmani

Reputation: 25

Service sharedpreferences updating value in activity

My service class can edit and store new value of sharedpreferences

so i want to retrieve it in another activity, its working fine.

Now what i would like to do, once service altered sharedpreferences, i want the sharedprefrences value to be updated in activity.

I used timer but it returns nullpointerexception. Any idea why?

Upvotes: 0

Views: 287

Answers (2)

user658042
user658042

Reputation:

Use an OnPreferenceChangeListener to monitor changes to your SharedPreference.

Upvotes: 1

Steve Bergamini
Steve Bergamini

Reputation: 14600

Not sure how a timer would help you in the scenario you've described. You may want to look into other options, such as:

  • Using a BroadcastReceiver
  • Binding the service to the activity & using the AIDL to define handlers.

Upvotes: 0

Related Questions