i'd do this with an AsyncTask and use the progress reporting feature to communicate state to the UI thread.
AsyncTask ftw! >OK I'm reading this page: >http://developer.android.com/guide/appendix/faq/commontasks.html#threading > >The code is as in the example (see below). In my application, the >worker thread has done loading of large bitmaps, and I need to notify >the UI thread the filename of the bitmap that was loaded as they get >loaded. How can I notify the UI thread of the filename of the bitmap >just loaded? I can see anyway to for updateResultsInUi() to be able to >take a parameter from the example below. > >public class MyActivity extends Activity { > > [ . . . ] > // Need handler for callbacks to the UI thread > final Handler mHandler = new Handler(); > > // Create runnable for posting > final Runnable mUpdateResults = new Runnable() { > public void run() { > updateResultsInUi(); > } > }; > > @Override > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > [ . . . ] > } > > protected void startLongRunningOperation() { > > // Fire off a thread to do some work that we shouldn't do >directly in the UI thread > Thread t = new Thread() { > public void run() { > mResults = doSomethingExpensive(); > mHandler.post(mUpdateResults); > } > }; > t.start(); > } > > private void updateResultsInUi() { > > // Back in the UI thread -- update our UI elements based on >the data in mResults > [ . . . ] > } >} > > > > -- jason.vp.engineering.particle --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

