使用以下代码:// to save in SharedPreferences in Loginprivate static final String MY_PREFERENCES = "MyPreference";private SharedPreferences sharedPreferences;sharedPreferences = getSharedPreferences(MY_PREFERENCES, MODE_PRIVATE);SharedPreferences.Editor editor = getSharedPreferences(MY_PREFERENCES, MODE_PRIVATE).edit();editor.putString("username", "usernameValue");editor.apply();//to get data from SharedPreferences in Home Pageprivate static final String MY_PREFERENCES = "MyPreference";private SharedPreferences sharedPreferences;sharedPreferences = getSharedPreferences(MY_PREFERENCES, MODE_PRIVATE); String username= SharedPreferences.getString("username", null);