0

開始値を変更するにはスタートカウントタイマー方式を使用したいが、それは機能しません。countdowntimerを使用したセッションタイムアウトの共有設定

private void startCountdownTimer(final String judul){ 
     countDownTimer = new CountDownTimer(120000, 1000) { 

      public void onTick(long millisUntilFinished) { 
       SharedPreferences pref = getActivity().getSharedPreferences("data", Context.MODE_PRIVATE); 
       SharedPreferences.Editor editor = pref.edit(); 
       editor.putString("click"+judul, "1"); 

      } 

      public void onFinish() { 
       SharedPreferences pref = getActivity().getSharedPreferences("data", Context.MODE_PRIVATE); 
       SharedPreferences.Editor editor = pref.edit(); 
       editor.putString("click"+judul, "0"); 
      } 
     }.start(); 
    } 

私は、そのような設定を変更するためにontickとonfinishメソッドを使用できますか?私は実際にアンドロイドでセッションタイムアウトを作りたいと思っています。だから私はそれを操作するカウントダウンタイマーを使用しています。このような

+2

より簡単です。あなたはeditor.commit()を使用しなければなりません –

+0

aw愚かな私 - _-ありがとう –

答えて

2

使用すると、あなたは、エディタに変更をコミットしていない

SharedPreferences pref = getActivity().getSharedPreferences("data", Context.MODE_PRIVATE); 
    pref.edit().putString("click"+judul, "1").commit(); 
関連する問題