Timer Vs thread sleep in Services

霸气de小男生 提交于 2019-12-24 09:27:15

问题


I need to check every 15 minutes a feed RSS file in order to update my application's results; I know I have to implement a service, but I was wondering which approach I should use to do this; is it better to implement a timer (http://developerlife.com/tutorials/?p=356) or a thread inside the service (http://www.youtube.com/watch?v=yfWsp9IHX1Y)? I tried the first tutorial but I get the error "Can’t create handler inside thread that has not called Looper prepare in Android"... What should I do? Stay stick with the first method or try the other one?


回答1:


You should use a PendingIntent and register it with the AlarmManager to be started 15 minutes in the future. This way your app won't use any ressources until the alarm fires.

You need to use the Intent that starts your Service to create the PendingIntent. After your service finished you need to reregister the PendingIntent for the next execution of your service.



来源:https://stackoverflow.com/questions/8267482/timer-vs-thread-sleep-in-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!