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. Can I use command to read/write volume on console ?

It for factory production, I need set max volume for testing, and then
recovery default volume.

So can I use command to read/write volume on console ?

-- 

2. Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml

Hi,
I'm trying to install a platform but when I type android the manager
loads then I click Available Software then select the
https://dl-ssl.google.com/android/repository/repository.xml repository
I get this error.,

Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml,
reason: HTTPS SSL error. You might want to force download through HTTP
in the settings.

So I click the settings tab and select the force through http then
click apply and save then nothing happens it doesn't save it because
if i then close it and reload it the checkbox is unticked so it's not
even using the force through http method. I get the same error if i go
straight back to available software.

I'm using Fedora and wget can download the xml file using ssl so I
don't know why it's getting this https ssl error.

Any ideas anyone?
Thank you

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

3. Horizontal Menu

4. Eclipse XML building super slow?

5. AIR for Android FAQs

6. Custom keyboard for only one EditText. Standard soft keyboard for other fields.

7. Need basic idea for Bubble popper game development