开发者

Should I do work in a separate thread if my android app has no UI?

My application is essentially a service that is sta开发者_C百科rted on boot (by a boot-completed receiver), and should periodically gather data, send it over the network, and go to sleep (probably using AlarmManager). It has no activities - no UI whatsoever.

Is there any reason to spawn an additional thread to perform the application logic? if not, where should I perform the logic? in the OnStart method?


Is there any reason to spawn an additional thread to perform the application logic?

Absolutely. Your service will be killed off if it fails to respond within 5-10 seconds. Nothing can tie up the main application thread for that length of time.

I recommend an IntentService for use with AlarmManager. In particular, if you want the device to stay awake while you are doing whatever it is you are doing, you might consider my WakefulIntentService.

Also, regarding "no UI whatsoever", if you plan on distributing this app via the Android Market, please bear in mind that users seem to dislike applications with no UI. They install it, get confused when there is no icon in the launcher, and give you a one-star rating. Even if you do not need a UI for actual operation, you might consider at least having some activity in the launcher, that shows documentation, perhaps a log of work being done, allows adjustment to the frequency of your work, etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜