Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #2825

Re: Threads and UI in Android

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.swapon.de!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 Sun, 03 Apr 2011 17:51:32 -0700
Organization A noiseless patient Spider
Lines 31
Message-ID <inb4mo$2br$1@dont-email.me> (permalink)
References <8vrrsdF6urU1@mid.individual.net> <8vs005F5tmU1@mid.individual.net> <inark9$gr4$7@lust.ihug.co.nz>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 4 Apr 2011 00:51:37 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="3ILfXhSA8cUOvYVoDoGUlw"; logging-data="2427"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CMyDXFkd7E8sAtYYVDbp+xQHmls9M1ZQ="
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 <inark9$gr4$7@lust.ihug.co.nz>
Cancel-Lock sha1:LdWiKkXYaD3qf1/sclRmBlvq19k=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2825

Show key headers only | View raw


On 4/3/2011 3:16 PM, Lawrence D'Oliveiro wrote:
> In message<8vs005F5tmU1@mid.individual.net>, Dirk Bruere at NeoPax wrote:
>
>> It would seem the answer is in here somewhere
>> http://developer.android.com/resources/articles/painless-threading.html
>
> Seems like AsyncTask is the way to go: it automatically divides up execution
> between a background thread and the UI thread, and takes care of all the
> synchronization between the two for you.
>
> How much more painless can you get? :)



Given that the OP want's to "constantly [check] for messages" I think 
the way he's doing it now is fine.  runOnUiThread() does the 
synchronization that he needs, and it seems cleaner than trying to wrap 
his deamon in an AsyncTask object and constantly call publishProgress() 
whenever he gets a packet.

Modern threading is getting sophisticated, and one sophisticated thing 
to do is to limit the number of threads so as to not overwhelm the OS. 
Limited thread pools are used for this purpose.  I don't know how 
AsynchTask is implemented, but if it uses a thread pool, you could 
easily starve your own app of threads for AsynchTask by permanently 
capturing too many AsynchTask threads, which is what the OP's task would do.

"Long running" tasks relative to the UI response time go in AsynchTask. 
  "Really long running" tasks, or permanent tasks like the OP's little 
network daemon, go in their own private thread.  Seems safest that way.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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