Wrox Programmer Forums
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 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 September 18th, 2012, 02:31 PM
Registered User
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Earthquake chapter 7 part 2


Can you guys get this to work as according to the book? I mean: with API 4 and 15?

I got it work after aa lot of time and then i ended up with the support library and a FragmentActivity instead of an Activity in Earthquake.java. Which... isn't the point of the exercise?

I thought the point of this exercise was to get it to work without using a support library. Can anybody help me getting it to work according to today's standard.

Here's my full version of the class:
package com.paad.earthquake;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.view.MenuItem;

public class Earthquake extends FragmentActivity {
	static final private int MENU_PREFERENCES = Menu.FIRST + 1;
	static final private int MENU_UPDATE = Menu.FIRST + 2;
	private static final int SHOW_PREFERENCES = 1;

	public int minimumMagnitude = 0;
	public boolean autoUpdateChecked = false;
	public int updateFreq = 0;

	public void onCreate(Bundle savedInstanceState) {


	public boolean onCreateOptionsMenu(Menu menu) {

		menu.add(0, MENU_PREFERENCES, Menu.NONE, R.string.menu_preferences);

		return true;

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

			Class c = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? PreferencesActivity.class
					: FragmentPreferences.class;
			Intent i = new Intent(this, c);

			startActivityForResult(i, SHOW_PREFERENCES);
			return true;

		return false;

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Activity.RESULT_OK)

		FragmentManager fm = getSupportFragmentManager();
		final EarthquakeListFragment earthquakeList = (EarthquakeListFragment) fm

		Thread t = new Thread(new Runnable() {

			public void run() {

	private void updateFromPreferences() {
		Context context = getApplicationContext();
		SharedPreferences prefs = PreferenceManager

		minimumMagnitude = Integer.parseInt(prefs.getString(
				PreferencesActivity.PREF_MIN_MAG, "3"));
		updateFreq = Integer.parseInt(prefs.getString(
				PreferencesActivity.PREF_UPDATE_FREQ, "60"));

		autoUpdateChecked = prefs.getBoolean(
				PreferencesActivity.PREF_AUTO_UPDATE, false);
Thanks in advance for any help/guidance with this problem!
Old October 31st, 2012, 05:54 PM
Registered User
Join Date: Jun 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts

When you say it doesn't work, what exactly do you mean? How far do you get? Is an exception being thrown? The version I just built works.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 Earthquake 2, Earthquake.java, error onActivityResult dbomberg BOOK: Professional Android 2 Application Development 2 November 30th, 2012 05:52 AM
Chapter 9 Earthquake 1 MellowFellow BOOK: Professional Android 2 Application Development 14 August 23rd, 2010 04:40 PM
Chapter 7 Part 2 Earthquake Exception clombardo BOOK: Professional Android 2 Application Development 3 April 29th, 2010 10:46 AM
Getting Exception after the Correction -for Chapter 6 Part 2 Earthquake project clombardo BOOK: Professional Android 2 Application Development 1 April 26th, 2010 06:03 AM
chapter 5 Earthquake EricTapia BOOK: Professional Android 2 Application Development 2 April 14th, 2010 12:47 AM

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