basteez
basteez

Reputation: 477

Thread doesn't start on Android

I have this piece of code into a ListFragment

@Override
public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   aa = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,  postTitleList);
   setListAdapter(aa);

   Thread syncThread = new Thread(new Runnable(){
       public void run()
       {
           syncPosts();
       }
   });
   syncThread.start();

   Log.d("POSTS", "Thread Status: " + syncThread.getState().toString());
   Log.d("POSTS", "Thread ID: " + Long.toString(syncThread.getId()));
}

but unfortunately the Thread never starts, it remains in WAITING status, is there a way to force it running?

Upvotes: 0

Views: 141

Answers (2)

basteez
basteez

Reputation: 477

After a lot of Log.d(), I found the problem: it was on line 58

if(child.getNodeName() == "title")

changing this line to

if(child.getNodeName().equals("title"));

everything works fine

Upvotes: 0

Gray
Gray

Reputation: 116918

I believe it is running. It is most likely getting into a WAITING state because something in syncPosts() is waiting on something. WAITING is the state you get when you are doing some object.wait(); and is waiting for someone to notify() it.

If you show some of the syncPosts() code we should be able to help you find the place where the thread is stuck.

Upvotes: 2

Related Questions