[Mono-bugs] [Bug 686305] Toast in IntentService not showing up...

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Apr 8 14:28:18 EDT 2011



Jonathan Pryor <jpryor at novell.com> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
                 CC|                            |jpryor at novell.com
         Resolution|                            |INVALID

--- Comment #1 from Jonathan Pryor <jpryor at novell.com> 2011-04-08 18:28:17 UTC ---
The problem is in the Handler documentation:


    "When you create a new Handler, it is bound to the 
    thread / message queue of the thread that is creating it"

Since you're creating the Handler instance within OnHandleIntent(), which is
invoked on the worker thread, you're thus creating a Handler bound to the
worker thread, which doesn't have a message queue, so nothing happens. :-)

The fix is to create the Handler instance on a thread which does have a message

    public class ToastService : IntentService
        Handler handler;

        public override void OnCreate ()
            base.OnCreate ();
            handler = new Handler ();

        protected override void OnHandleIntent(Intent intent)
            handler.Post(() => {
                Toast.MakeText(this, "Pass the TOAST!  2",

This allows the Toast messages to be seen, as desired.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list