Well, if you don't handle that, it will leak. Preferably, you should
be passing the application's context and not the activity's context.
Since, Activity's context depends on the state of the particular
activity, and the context you are probably interested in inside the
Worker thread is most of the times an application context.

On Jan 10, 6:09 pm, Shawn Brown <big.coffee.lo...@gmail.com> wrote:
> 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....

-- 
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