In this case you wouldn't delegate displaying of a toast to an activity.
 You do, however, need to do this in a thread that is running a message
loop.  That is why it is saying you need to call Looper.prepare() -- that
sets up a message loop for a thread.

If this thread is doing background work like networking, though, you
probably don't want it to run a message loop because the whole point of
having the thread is of course that it won't provide a responsive UI so it
won't provide a responsive message loop for the toast.  In that case, you'll
want to just execute your toast code on the main UI thread.  AsyncTask makes
this easy.  To roll your own, you can just make a static Handler variable
that you post a message to and it takes care of the toast.

static Handler sHandler = new Handler();

// In your thread
sHandler.post(new Runnable()) {
    @Override void run() {
        // Display the toast.
    }
}


On Mon, May 30, 2011 at 6:41 AM, Mark Murphy <[email protected]>wrote:

> On Mon, May 30, 2011 at 9:32 AM, Mark Cz <[email protected]> wrote:
> > Hi,
> > I have an Android Service that does some client-server work,
> > E.g I am getting a file from the server, and I want to toast a message
> > - "Download was completed"
>
> A service should not be updating the user interface. Please delegate
> that to an activity if one of yours is in the foreground, or display a
> Notification if there is no such activity and you feel the situation
> warrants a Notification. You can use an ordered broadcast to achieve
> this:
>
>
> http://commonsware.com/blog/2010/08/11/activity-notification-ordered-broadcast.html
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android Training in Oslo: http://bit.ly/fjBo24
>
> --
> 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
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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