How to create a Toast from a background operation?

by Mariano Kamp » Sat, 02 May 2009 01:40:40 GMT


Sponsored Links
 Hi,
  what is a good way to signal an error from a thread that is not the UI
thread and you don't know which activity/handler is currently active? Can I
somehow get eleto the current UI thread?

  Can I somehow use the MainLooper from the application context?

  I use notification for serious events where the user needs to take action,
e.g. a login failed, but here I am looking for a transient notification with
a toast and it would be ok if the toast is not seen in some cases.

Cheers,
Mariano

--~--~---------~--~----~------------~-------~--~----~



How to create a Toast from a background operation?

by Mark Murphy » Sat, 02 May 2009 01:44:40 GMT


 


Does it matter?

I have not tried to have a background thread use a Handler or
runOnUiThread() of an Activity that might not be active. It is entirely
possible "it just works", and so you can use whatever Activity you have
handy.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books.html 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


How to create a Toast from a background operation?

by Mark Murphy » Sat, 02 May 2009 02:07:26 GMT


 


It looks like you are trying to manually instantiate a Handler, or
possibly an Activity, in the background thread. If so, that is not the
proper way to use a Handler. This is one of the reasons I dislike
Handler, preferring runOnUiThread() (and hopefully the new AsyncTask).


Doubtful. Otherwise, AsyncTask couldn't work.


Can you use AsyncTask for this? The result of your background work would
 be passed to onPostExecute(), which could then display an error on the
UI thread if something failed in the background thread.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books.html 

--~--~---------~--~----~------------~-------~--~----~



How to create a Toast from a background operation?

by Mark Murphy » Sun, 03 May 2009 06:08:37 GMT


 


Why not keep a log of failures and display it to the user when they next
launch your application? Or at least have that as an option.

I agree with Raphael -- popping up Toasts in the background would be
annoying to me as a user.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Warescription: Three Android Books, Plus Updates, $35/Year

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to force screen to switch between landscape/portrait

Is there a way to programmatically force the screen to change between landscape 
and portrait mode? I want to allow the user to choose a menu item to rotate the 
screen, instead of relying on pulling out the keyboard.

I am looking for something like Activity.changeScreenOrientation, but couldn't 
find such a thing in the API docs ...

Thanks


      

--~--~---------~--~----~------------~-------~--~----~

2. Capturing PCM/YUV samples,encoding, writing in a specific format

I have built PV core outside android. i would like to know how to make
the core accept data from the mic or camera-> encode it in a specific
format -> write in a specific file format.

What should I do to have a working graph like this ?
Source -> microphone
sink-> file writer (3gp)
interim-> amr codec
--~--~---------~--~----~------------~-------~--~----~

3. Problem with textalign

4. Questions in Calling Operation

5. why Android disable wlan interface when receive EVENT_SUPPLICANT_DISCONNECT

6. Distributing

7. how to see sms file.