Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #2823
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Threads and UI in Android |
| Date | 2011-04-03 17:29 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <inb3eg$s8f$1@dont-email.me> (permalink) |
| References | <8vrrsdF6urU1@mid.individual.net> <8vs005F5tmU1@mid.individual.net> |
On 4/3/2011 12:27 PM, Dirk Bruere at NeoPax wrote:
>> So far so good - no problems.
>> However, if the Android ListView in the UI is to be updated with this
>> data there is a problem. I cannot go in and do stuff to the ListView
>> from BlinkAPI or I get a message about "called from wrong thread".
This seems analogus to Java Swing & EDT. Use the Activity.runOnUiThread
method to send processing to the UI thread, so you won't get this message.
Given:
some other thread
|
|
V
public void someMethod( Params.... ) {
// do set up
// do this on UI thread
// do clean up
}
Transform this to:
some other thread
|
|
V
public void someMethod( Params.... ) {
// do set up
Activity.runOnUiThread( new Runnable() {
public void run() {
// do this on UI thread
}
} );
// do clean up
}
To run the center bit of code on the UI thread. Note that you are
executing code asynchronously and the "clean up" will likely happen
before the UI thread bit. Something to be aware of.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-03 19:16 +0100
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-03 20:27 +0100
Re: Threads and UI in Android Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-04-04 10:16 +1200
Re: Threads and UI in Android markspace <-@.> - 2011-04-03 17:51 -0700
Re: Threads and UI in Android "John B. Matthews" <nospam@nospam.invalid> - 2011-04-03 21:50 -0400
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-04 06:23 +0100
Re: Threads and UI in Android Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-04-04 18:48 +1200
Re: Threads and UI in Android markspace <-@.> - 2011-04-04 17:31 -0700
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-04 19:18 +0100
Re: Threads and UI in Android markspace <-@.> - 2011-04-04 14:54 -0700
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-04 23:41 +0100
Re: Threads and UI in Android markspace <-@.> - 2011-04-04 16:29 -0700
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-05 00:32 +0100
Re: Threads and UI in Android markspace <-@.> - 2011-04-04 17:27 -0700
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-05 01:30 +0100
Re: Threads and UI in Android Steve Sobol <sjsobol@JustThe.net> - 2011-04-04 18:53 -0700
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-05 03:19 +0100
Re: Threads and UI in Android Steve Sobol <sjsobol@JustThe.net> - 2011-04-04 23:04 -0700
Re: Threads and UI in Android Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2011-04-05 08:04 +0100
Re: Threads and UI in Android markspace <-@.> - 2011-04-03 17:29 -0700
csiph-web