Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Android Application Development
|
BOOK: Beginning Android Application Development
This is the forum to discuss the Wrox book Beginning Android Application Development by Wei-Meng Lee; ISBN: 978-1-1180-1711-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Android Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2012, 01:46 PM
Registered User
 
Join Date: Jun 2008
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chap. 4: Why is handler needed with progress bar?

Hi, All:

In the code in chapter 4, on p. 175, the author keeps instantiating a new Runnable, everytime through the loop, to set the progress of the progress bar. Isn't that inefficient? i.e., why can't he just write:

progressStatus = doSomeWork();
progressBar.setProgress(progressStatus);

Instead of having to wrap the second line in a handler:

Code:
progressStatus = doSomeWork();
handler.post(new Runnable()
{     
     public void run(){
          progressBar.setProgress(progressStatus);
     }
});
Any insights would be appreciated.

Thanks,

Michael
 
Old January 1st, 2013, 07:18 PM
Registered User
 
Join Date: Apr 2012
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default

The handler function is used for the android system to communicate between threads. Since the code starts the code in a second parallell executed thread it use the handler to transfer information back to the UI-thread.
The reason to have it in a second thread is that if an activity takes more than 5 seconds to execute in the main UI thread the Android system will stop the your activity will be killed and an error message will apair in the device window
The Following User Says Thank You to BjörnWagner For This Useful Post:
mprogers (January 6th, 2013)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Progress Bar toekneel Crystal Reports 0 October 19th, 2004 11:04 AM
Progress Bar kevind23 Classic ASP Basics 1 May 24th, 2004 08:00 AM
Progress Bar BSkelding ASP.NET 1.0 and 1.1 Basics 3 May 4th, 2004 04:12 AM
Progress Bar Help jacob_d_99 Javascript How-To 1 November 20th, 2003 11:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.