public class Config { private static final String TOKEN_KEY = "token"; private static final String APP_ID = "com.jiangcun.secret"; public static String getCacheToken(Context context){ return context.getSharedPreferences(APP_ID , Context.MODE_PRIVATE).getString(TOKEN_KEY,null); //根据 Token_KEY 获取token. } public static void cacheToken(Context context,String token){ //传入token,保存 SharedPreferences.Editor editor = context.getSharedPreferences(APP_ID,Context.MODE_APPEND).edit(); editor.putString(TOKEN_KEY,token); editor.commit(); } }