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"; public static SharedPreferences.Editor sPEditor; public static SharedPreferences sharedpreferences; /** * Add protein to today's Protein Counter. */ public static float addToProtToday(Context c, float toAdd) { sharedpreferences = c.getSharedPreferences(SHARED_PREF_FILE_NAME, 0); float result = toAdd + getProtToday(c); sPEditor = sharedpreferences.edit(); sPEditor.putFloat(PROT_TODAY_PREF_NAME, result); sPEditor.commit(); return result; } 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; } }