View Single Post
  #1 (permalink)  
Old September 18th, 2012, 02:31 PM
layingincouch layingincouch is offline
Registered User
Points: 55, Level: 1
Points: 55, Level: 1 Points: 55, Level: 1 Points: 55, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
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 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.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
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!
Reply With Quote