我有點卡在這一個,它不是太複雜,但它讓我捱打! 我想要做的是恢復用戶的會話,獲取最後一個活動的名稱,然後將其傳遞給意圖。
我被卡住的地方在於將檢索到的字符串轉換爲類名,因此resumeIntent可以使用它。將字符串值轉換爲Java類名稱
public void Resume (View view){
SharedPreferences sharedPref =
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
String resumeName = sharedPref.getString("ActivityName", null);
//probably need to do something here//
Intent resumeIntent = new Intent (this, resumeName);
startActivity(resumeIntent);}
你嘗試過'新的意圖(這,Class.forName(resumeName))'? – Panther
Thankyou非常,它完美的作品:) –