Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Threads and UI in Android Date: Mon, 04 Apr 2011 17:31:24 -0700 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: <8vrrsdF6urU1@mid.individual.net> <8vs005F5tmU1@mid.individual.net> <8vt2tjFcvhU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 5 Apr 2011 00:31:30 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="GJOQD5qMhajTRok5p45vaQ"; logging-data="31532"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JnIBZxvnA9DIBgEXdOmRDK1O05C6A/Ic=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Cancel-Lock: sha1:9osPQXsBA1wFkdXjUOi+zI6dEbs= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2869 On 4/3/2011 11:48 PM, Lawrence D'Oliveiro wrote: > In message<8vt2tjFcvhU1@mid.individual.net>, Dirk Bruere at NeoPax wrote: > >> Where linkAPI.updateIncomingData(packetStr); is the offending bit since >> it triggers updates on the UI thread. >> >> That would be where I use runOnUiThread()? > > OK, if it’s running in an endless loop, I guess that’s not suitable for an > AsyncTask. > > I believe the recommended mechanism for posting actions back to the UI > thread is via a Handler > : create > this from the UI thread, pass it to the background thread, and the latter > can use the post method to send back a Runnable to be executed. I don't like this idea. I'd bet that the UI thread already has a handler; it seems the intelligent thing to do. And I'd bet too that the handler for the UI is publicly available, in some publicly documented API. And I'll further suppose that they called the public method to access the UI handler "runOnUiThread". So don't do this, because you're just reinventing a perfectly good wheel.