Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; public class Main { private static final String SHARED_PREF_FILE_NAME = "ProteinTacking"; private static final String PROT_TODAY_PREF_NAME = "ProteinToday"; private static final String PROT_GOAL_PREF_NAME = "ProteinGoal"; public static SharedPreferences sharedpreferences; public static String getProgress(Context c) { float ProtToday = getProtToday(c), ProtGoal = getProtGoal(c); float perc = ProtToday / ProtGoal * 100; return (int) ProtToday + "g / " + (int) ProtGoal + "g (" + (int) perc + "%)"; } public static float getProtToday(Context c) { sharedpreferences = c.getSharedPreferences(SHARED_PREF_FILE_NAME, 0); float result = sharedpreferences.getFloat(PROT_TODAY_PREF_NAME, 0); //Log return result; } public static float getProtGoal(Context c) { sharedpreferences = c.getSharedPreferences(SHARED_PREF_FILE_NAME, 0); float result = sharedpreferences.getFloat(PROT_GOAL_PREF_NAME, 9999);//9999(magic number) is error number meaning no goal has been set yet ie: promt the wizard return result; } }