开发者

Android: restart remote service and bind it again

开发者 https://www.devze.com 2023-02-10 02:43 出处:网络
I have a remote service in android. It\'s binded to my list activity and sends some messages to it. The service contins scheduled task in it. I also have preference: refresh interval for my service. A

I have a remote service in android. It's binded to my list activity and sends some messages to it. The service contins scheduled task in it. I also have preference: refresh interval for my service. All I want is to restart the service when user changes refresh interval. Butif I do it in onSharedPreferenceChanged() then I loose the connection from my list activity. How can I solve it? Thanks.

I know th开发者_开发技巧at I can use Broadcast Reciever. Is there another way?


I have a remote service in android.

Why? Why not a local service?

The service contins scheduled task in it.

Why? Why not use AlarmManager, so your service isn't just sitting around in RAM, watching time pass?

All I want is to restart the service when user changes refresh interval.

Why? Why not just change your AlarmManager schedule? If you use a local service, your service can use a SharedPreferences and setOnSharedPreferenceChangeListener() to be automatically notified of changes in the refresh interval.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号