p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Android 4 Application Development (http://p2p.wrox.com/forumdisplay.php?f=685)
-   -   Chapter 7 - Earthquake example question (http://p2p.wrox.com/showthread.php?t=90540)

marfl99 July 17th, 2013 07:25 AM

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

Android23Geek July 24th, 2013 08:58 AM

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.

neilw August 21st, 2013 11:12 AM

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);

neilw September 4th, 2013 09:07 AM

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.

uler3161 September 4th, 2013 01:20 PM


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.

neilw September 4th, 2013 02:14 PM

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);


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.


uler3161 September 4th, 2013 02:40 PM

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.

marfl99 September 9th, 2013 07:49 PM

We look forward to it...
We look forward to getting right code or any updates.

Thank you

All times are GMT -4. The time now is 08:32 PM.

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