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. getView from CustomizedAdapter called several times

Hi Everyone,

I am implementing my own adapter that inherits from BaseAdapter (this
is something very classic).
Then when I start the activity that owns the listView binded to this
adapter I can see that the getView() method is called more times than
what the number of view actually available in the list.
For instance, I do have 2 rows in my list and when I first set the
adapter getView is called 6 times. Then If I make a call to
notifyDataSetChanged(), getView is called 4 times.
I understand that when you scroll up and down getView must be called
to generate or re use a view but I don't scroll up or down, I am
really wondering why getView is called so many time.

Thanks a lot in advance for your responses.

My code just in case even though it is a pretty basic piece of code:

        public View getView(int position, View convertView, ViewGroup
                ViewHolder holder;
                if (convertView == null)
                        convertView = mInflater.inflate(R.layout.row_action, 
                        // Creates a view holder
                        holder = new ViewHolder();
                        holder = (ViewHolder)convertView.getTag();
                        return convertView;


2. How to retain EditText data when "BACK" key is pressed

> But the thing i think , i am not using properly is onSaveInstanceData

They are there for cases where Android, and not the user, decides to close
the activity. The most common case for this is when the screen orientation
changes (e.g., user slides out the keyboard on a G1).


Because that is not the purpose of that method.

Mark Murphy (a Commons Guy)
Android App Developer Books: http://commonsware.com/books.html


3. How can use android native dialer to manage call events in our own way

4. Intent.ACTION_SEND problems with platform\emulator 1.1

5. GLES applications sometimes crashes "(SIGSEGV), fault addr 00000150" after turning screen off/on

6. How can I know if I can display a character ?

7. Problem in simple Code SQLite