A timer thread and url fetch thread in same activity.

by Droid » Fri, 20 May 2011 04:57:45 GMT

Sponsored Links
 I am having problems with a timer that should fetch http results from
the web every 5 minutes.
I having problems with two threads - often I cannot even turn them off
or keep the timer going without upsetting the apple cart.

Should I start using wait() and notify(), a separate service or
continue trying to get them to be friends with each other in the same
activity. At present its all very badly behaved and I feel as though I
am juggling with marbles.


Re: A timer thread and url fetch thread in same activity.

by TreKing » Fri, 20 May 2011 05:06:37 GMT


Just saying you're using two threads is a red flag. What apple cart?

Use a handler to schedule a message to go off in 5 minutes. When that
message is delivered, use an AsyncTask to do the fetch and handle the
results when it completes.

No raw threads necessary.

TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices


Sponsored Links

Other Threads

1. Speed difference between DOM and SAX parser for small documents


currently, we use the SAX parser bundled with Android to parse XML
coming from our servers. We found however that parsing the XML using a
SAX handler is prone to errors and difficult to maintain. Therefore I
thought about switiching to a DOM parser, and probably also a wrapper
around it (like JDOM) for convenience.

But, does anyone know how big the performance impact will be? Is it
negligible for documents that are merely 10-50k in size? I remember
that in early alphas of Android, the DOM parser was noticeably slower,
but I also heard that this has become better meanwhile.


2. Problem when updating ListView

Hi all,

I have a ListView with a footer View that is bind to a custom
ArrayAdapter within a ListActivity. When creating the activity, I fill
in the ArrayAdapter with some items through a dedicated thread. At the
end, the thread calls setListAdapter and requestFocus through a
handler. At this point, everything works fine. I mean, when scrolling
the ListView, all items get hilighted correctly, even when the footer
view gets focused. Now, I need to update the items in the ListView by
adding a few items more. Again, I use a thread to update the
ArrayAdapter and use a handler to post invalidate() on the ListView.
Now, when I scroll down the ListView and reach the footer view, the
last item of the list gets unreadable when losing focus. The same
happens with the first item of the list when reaching a header view or
a parent tab. I tried requestFocus() again but it didn't work. I also
tried android:drawSelectorOnTop="false" with no more result.

Any guess? Help is welcomed.


3. iPhone Flops in India

4. How to update the SDK

5. ContentProvider instance

6. Building a .so lib

7. emulator support in 2.6.27 ?