Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 4 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 17th, 2013, 07:25 AM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 7 - Earthquake example question

I'm on page 240 of the book following the earthquake example. When I go to the number 6 Update the onActivityResult Handler I don't understand why in the book there is a "Thread t" and in the code example there isn't one?

Why is the code in the book different than the code available for download?

At the end of this example the book refers to Chapter 7 Earthquake Part 2. I imported the example into Eclipse, and I don't see the same code. Why?

Thanks in advance
__________________
Marcelo Oliveira
MAOWebSolutions.com
Reply With Quote
  #2 (permalink)  
Old July 24th, 2013, 08:58 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Location: Netherlands
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
Default

I can't answer that, only Reto can. He has a profile on Google+. The book is correct, you have to invoke network requests on a separate thread. I can give an educated guess. I think that you can invoke network requests on the main thread if you do not specify a <uses-sdk> permission in the project's androidmanifest.xml file.
Reply With Quote
The Following User Says Thank You to Android23Geek For This Useful Post:
marfl99 (August 22nd, 2013)
  #3 (permalink)  
Old August 21st, 2013, 11:12 AM
Registered User
Points: 41, Level: 1
Points: 41, Level: 1 Points: 41, Level: 1 Points: 41, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
Kind of similar to the above answer, quite possibly because from ICS networking has to be done on a separate thread (Gingerbread did not) the book was updated but the samples not.

In order to get it working without threads on ICS upwards without threads (but really only for testing purposes) you should add to the onCreate event:

StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().buil d(); StrictMode.setThreadPolicy(policy);
Reply With Quote
The Following User Says Thank You to neilw For This Useful Post:
marfl99 (August 22nd, 2013)
  #4 (permalink)  
Old September 4th, 2013, 09:07 AM
Registered User
Points: 41, Level: 1
Points: 41, Level: 1 Points: 41, Level: 1 Points: 41, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

I've just been trying the code properly and for some reason Wrox, Reto and the entire Technical proof reading team have failed to test the download code.

Essentially, the download code for chapter 7 removes all the threading/handler code.

The only solution is to get the earlier code (or type it in) and take it from there.

My worry is every chapter from now one will also have the duff code.

Thanks for wasting an afternoon of my time Wrox.
Reply With Quote
  #5 (permalink)  
Old September 4th, 2013, 01:20 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am the tech editor for the book and I understand your frustration. Though I don't think it's a matter of the downloaded code removing the threading/handling. The original draft of the book did not have the threading code and I requested that it be put in, which it was. Apparently the downloaded code is the original version, but it wasn't something I was given to review, so I didn't know there was a problem. I will check with Reto to see if he can provide the correct version.

As for the other code examples, I will assume they are also earlier code, so any network access should be done on a separate thread.

Sorry for the troubles.
Reply With Quote
  #6 (permalink)  
Old September 4th, 2013, 02:14 PM
Registered User
Points: 41, Level: 1
Points: 41, Level: 1 Points: 41, Level: 1 Points: 41, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
Thanks for the reply. But no, later chapters don't work either. Well it seems something has been done to address threading but not quite:

I'm doing chapter 8 and while the EarthQuakeListFragment has reinstated the threading (which I'm guessing means chapter 8 has been updated for the later version of android?) the code in the main activity Earthquake.java forgets to do this in the code returning back from preferences:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

........
earthquakeList.refreshEarthquakes();
}

It would be nice if you could update the errata to include a fix for the earthquake feed causing a null pointer exception due to the xml generating a 'deprecated feed' xml entity.

thanks.
Reply With Quote
  #7 (permalink)  
Old September 4th, 2013, 02:40 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've sent Reto a message about the code. What's available to download is something I'm not really in control over, just editing what is sent to me, so he will probably have to handle it.

If it's the downloaded code for later chapters that isn't working, then it's probably the same problem with earlier code than the book. I tried to make sure everything that was in the book copy was tested. But that doesn't mean I didn't overlook a snippet or that my edit made it in the final copy.

The earthquake feed is another thing Reto will probably have to address since it's his example. If I hear back from him on updating the code, I'll mention that as well since it will be a problem for anyone using the book at this point.
Reply With Quote
  #8 (permalink)  
Old September 9th, 2013, 07:49 PM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default We look forward to it...

We look forward to getting right code or any updates.

Thank you
__________________
Marcelo Oliveira
MAOWebSolutions.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Earthquake Chapter 6 newbie123 BOOK: Professional Android 4 Application Development 7 January 21st, 2013 06:09 AM
Chapter 7 Earthquake 2, Earthquake.java, error onActivityResult dbomberg BOOK: Professional Android 2 Application Development 2 November 30th, 2012 04:52 AM
Chapter 9 Earthquake 1 MellowFellow BOOK: Professional Android 2 Application Development 14 August 23rd, 2010 04:40 PM
Please help: Chapter 9 Earthquake 4 dahe BOOK: Professional Android 2 Application Development 0 July 21st, 2010 03:41 PM
chapter 5 Earthquake EricTapia BOOK: Professional Android 2 Application Development 2 April 14th, 2010 12:47 AM



All times are GMT -4. The time now is 12:36 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.