Reputation: 11975
I have an Activity
and several remote services that should be running even if the Android app is not running. I need the services to listen for changes in the SharedPreferences
of the main Activity
(when this is running), but how can I do this?
BroadcastReceiver
? IPC communication? Not sure..
Could you please give me a hand here?
Thanks a lot, Manu.
Upvotes: 0
Views: 896
Reputation: 1007296
I have an Activity and several remote services that should be running even if the Android app is not running.
First, you do not need "several remote services" in the first place. At most, you need several services that are not remote. Being remote has absolutely nothing to do with "should be running even if the Android app is not running". You are wasting a lot of RAM, CPU, and battery this way.
Second, since neither the user nor the OS wants "several" services "running even if the Android app is not running", please try to consolidate them into one service and only have that service when it is actively delivering value to the user. For example, watching the clock tick is NOT actively delivering value to the user -- use AlarmManager
for that.
I need the services to listen for changes in the SharedPreferences of the main Activity (when this is running), but how can I do this?
Make them no longer be remote services, then have the service(s) register an OnSharedPreferenceChangeListener
with the SharedPreferences
to find out about preference changes.
Upvotes: 1