Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; public class Main { public static final String TRAINING_WORDS_COUNT = "TRAINING_WORDS_COUNT"; static public int TRAINING_VIEW_PAGER_COUNT = 5; public static int getTrainingWordsSetting(Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); String count = preferences.getString(TRAINING_WORDS_COUNT, Integer.toString(TRAINING_VIEW_PAGER_COUNT)); try { return Integer.parseInt(count); } catch (NumberFormatException ex) { return TRAINING_VIEW_PAGER_COUNT; } } }