2016-12-02 16 views
-2

動作しない私は、このメソッドを置く:セーブ/ロードの活動で最初の打ち上げはMainActivityの最初の起動時に

startChoice = SharedUtilities.getInstance().getChoice(getApplicationContext()); 
     if(startChoice ==""){ 
      start(MainActivity.this,RegistrationActivity.class); 
     }else{ 
      ........ 
} 

これは、文字列startChoice

public String getChoice(Context context) { 
     appSharedPrefs = context.getSharedPreferences("PsiceToday",Context.MODE_PRIVATE); 
     thisChoise = appSharedPrefs.getString("Choice",""); 
     return thisChoise; 
    } 

方法を取得するための方法であり、 start(MainActivity.this、RegistrationActivity.class)はデバッグstartChoiseで ""と等しくないため呼び出されません。

実装で何か問題があったと思いますか?

+2

'startChoice.equals(" ")' –

答えて

1

は、あなたがそれを使用したい場合は、この

はここutilsのクラスメソッド

public static String ReadSharePrefrence(Context context, String key) { 
//  SharedPreferences read_data = context.getSharedPreferences(
//    Constant.SHRED_PR.SHARE_PREF, context.MODE_PRIVATE); 
// 
//  return read_data.getString(key, ""); 

     String data; 
     final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); 
     final SharedPreferences.Editor editor = preferences.edit(); 
     data = preferences.getString(key, ""); 
     editor.commit(); 
     return data; 
    } 

で試してみてください。

String value = Utils.ReadSharePrefrence(this,Constant.KEY); 
if(value.equalsIgnoreCase("")){ 
//put your code 

}else{ 
//put your code. 

} 

これは私の仕事でした。

+0

ありがとう、それは仕事です – Marduk