开发者

Never Ending background thread?

I currently have a listview that is populated upon creation from a web server. I want it to either poll the database 开发者_如何转开发for updates routinely, or to allow a php script to update it. I would prefer that it be updated by the database, rather than polling.

As far as polling goes I know that I can implement a service or an asyncthread. I also have found the timertask class.

For AsyncThread: Can I have this be recurring continuosly? Would I call the .start method from the

For TimerTask: Is this less efficient than an asyncthread or service?

Also do I need to create the TimerTask inside of a thread? or will it create its own threads?


Trying to turn a server into a client, and a client into a server, is like trying to eat through the wrong orifice. It's fighting against the nature of the original design.

For one thing, you can't rely on your application to be on continuously, not on a phone anyway. Applications on cell phones have low priority. Applications on cell phones have limited energy they can use. Applications on cell phones are also not always going to be connected to the internet.

So for one thing, you'll want to use a Service on its own thread (you can use AsyncTask if you like). Your service will need its own thread so it doesn't block the UI thread waiting for responses. And you'll want to use AlarmManager to wake up or terminate your Service as needed (since your Service is bound to get killed a few times, through no fault of its own).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜