2017-02-18 7 views
0

私はこの1つに固執していますが、それほど複雑ではありませんが、殴られてしまいました! 私がやろうとしているのは、最後のアクティビティの名前を取得してからインテントに渡すことで、ユーザーのセッションを再開することです。
私は立ち往生していますが、取得したStringをクラス名に変換しているので、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);} 
+2

あなたは '新しい意図(this、Class.forName(resumeName))'を試してみましたか? – Panther

+0

大変ありがとうございます、それは完璧に動作します:) –

答えて

3

てみてください::

Intent resumeIntent = new Intent (this, Class.forName(getPackageName() + resumeName); 
startActivity(resumeIntent); 

UPDATE

String resumeName = YourActivityName.class.getCanonicalName(); 
try { 
    Class newClass = Class.forName(resumeName); 
    Intent resume = new Intent(this, newClass); 
    startActivity(resume); 
} catch (ClassNotFoundException e) { 
    e.printStackTrace(); 
} 

ストア文字列変数の活動の標準名。

+0

ありがとう、それは参考になりました。 –

+0

もちろん。問題が解決して問題が解決した場合は、これを承認済みの回答としてマークしてください。 – Bayou

関連する問題