On Fri, Mar 25, 2011 at 10:47 AM, Tobiah <[email protected]> wrote: > That's basically what I'm doing. >
Not really. Your code showed an infinite loop with no way of breaking out. You need *some* way for your task to complete. > I take it that the boolean argument to cancel() just gets me a quicker exit > rather than waiting for the sleep to continue? > Basically, yes. Also note that sleep() is not the only interruptible state. I think wait() and join() are as well, so it depends how complicated you're getting with task's thread. > Although, that seems like a strange use of AsyncTask. >> > > I have a ListView that displays a list of people. While that Activity is > visible, it is possible for another thread to query a server and get another > person. The AsyncTask in question queries the database once a second to see > whether there are any new records. If there are, the ListView > updates accordingly. Is that strange? > I think so. In my mind an AsyncTask represents a single, executable action that does one thing that may take a while and then exits. I wouldn't use it to do a looping action like this. If this other thread queries your servers and finds a new person, I would post a message on a Handler to indicate to your Activity to add the new person. No need to hit the DB every 1 second. > Also, what of my choice to check the database once a second? > Terrible :-) See above comment. > To often? Can I go to 1/10 of a second without impacting CPU or battery > usage? > Yes, too often, IMO. Any extra work you do uses the CPU which uses the battery. ------------------------------------------------------------------------------------------------- TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

