Hi,

Android docs(1) suggest using threads and a handler to send messages
(to avoid ANR).

Fine.  I've always done that but then porting some code to Android
noticed that it's not necessary.

Passing the Activity (i.e. Context) works fine.

public class WorkerThread extends Thread {

    private Activity mActivity;

    public WorkerThread(Activity mActivity) {
        super();
        this.mActivity = mActivity;
    }

 @Override
    public void run() {
      mActivity.showToast("WorkerThread thread says hello");  //
displays a message
      //setting a TextView works fine too
...
}

I understand the potential for memory leaks (2), but if I control the
WorkerThread lifecycle (it dies when the the Activity  pauses), then
really there is no need to use a handler, is there?  Or do I
misunderstand?

Shawn

(1) Handling Expensive Operations in the UI Thread -
http://developer.android.com/guide/appendix/faq/commontasks.html
(2) http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to