Again, I found the solution before the post made it through
moderation. Anyway, the workaround I found was to use a
android.os.Handler and use the postDelayed() function within it. If
anyone knows a better solution, please let me know.

On Sep 13, 3:54 pm, Felix Oghina <[email protected]> wrote:
> My Activity fetches an XML from the Web, parses it and displays
> information in a ListView. Everything was working fine until I decided
> to do the XML fetching and parsing in a TimerTask, so that I could
> show a "Loading..." message while that is happening. After lots of
> debugging, I realized that the application hangs on
> mListAdapter.add(mCurName), where mListAdapter is an
> ArrayAdapter<CharSequence> and mCurName is a String. This instruction
> worked before using a TimerTask, but now it just stops execution
> without any exception or anything. I have tried creating the Timer
> with both new Timer(true) and new Timer(false), but nothing seems to
> work.
>
> Note: the mListAdapter.add(mCurName) call is actually made in a
> function within my main Activity class, which, in turn, is called from
> the run() function inside the TimerTask class that is defined within
> my main Activity class. Just to make sure I made sense, here's a
> sketch of my code:
>
> public class MyActivity extends Activity {
>         // vars...
>         protected void onCreate(Bundle savedInstanceState) {
>                 // stuff...
>                 Timer timer = new Timer(true);
>                 SearchTask task = new SearchTask();
>                 timer.schedule(task, 1);
>         }
>         public void run() {
>                 // stuff...
>                 mResultList = parseResponseXml(responseXml);
>                 // other stuff, but execution never reaches this point...
>         }
>
>         public class XmlHandler extends DefaultHandler {
>                 // vars...
>                 public void startElement(...) {...}
>                 public void characters(...) {...}
>                 public void endElement(String uri, String name, String qName) 
> {
>                         // stuff...
>                         if (name == "resource") {
>                                 inResource = false;
>                                 if (inResults) { // this is where the problem 
> is
>                                         Log.i("TasteKidDebug", "Before 
> mListAdapter.add"); // this gets logged
>                                         mListAdapter.add(mCurName);
>                                         Log.i("TasteKidDebug", "After 
> mListAdapter.add"); // this doesn't
>                                         mResults.add(mCurName, mCurType);
>                                 }
>                         }
>                         // stuff..
>                 }
>         }
>
>         public ResourceList parseResponseXml(String xml) throws Exception {
>                 // stuff...
>                 XmlHandler handler = new XmlHandler();
>                 xr.setContentHandler(handler);
>                 xr.parse(new InputSource(new StringReader(xml)));
>                 return handler.mResults;
>         }
>
> }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to