2017-08-13 19 views
-1

私は1日にアプリを訪れた時間がどれくらいかかり、共有された環境設定が毎日リセットされるはずのアプリを作りたいと思っています。つまり、毎日0から自動的にカウントを開始します。共有の設定を使用してどうすればよいですか。以下はコードです私は毎日アプリを開く回数をカウントしたい

prefs = getPreferences(Context.MODE_PRIVATE); 
    editor = prefs.edit(); 
    // editor.clear(); 
    totalCount = prefs.getInt("counter", 0); 
    totalCount++; 
    editor.putInt("counter", totalCount); 
    editor.commit(); 

Toast.makeText(getApplicationContext(),"Hello User..!! You have entered the App " +totalCount+ " time today",Toast.LENGTH_LONG).show(); 
+0

**カウンター**として保存する代わりに、** [何らかのフォーマットの日付] - カウンター**として使用できます。これは毎日入手できます –

+0

どうすればいいですか?あなたは教えてくれますか? @MuthukrishnanRajendran – Abhi

答えて

0

このように試してみると、毎日追跡できます。過去の日数も取得できます。

String formattedDate = new SimpleDateFormat("ddMMMyyyy").format(new Date()); 
String counterKey = formattedDate + "-counter"; 

prefs = getPreferences(Context.MODE_PRIVATE); 
editor = prefs.edit(); 
// editor.clear(); 
totalCount = prefs.getInt(counterKey, 0); 
totalCount++; 
editor.putInt(counterKey, totalCount); 
editor.commit(); 

でも、SQLiteデータベースを試すことができます。複数の日のために格納し、検索する。

+0

これは働いて..!アクティビティのリストビューでカウント日を賢明に表示できますか? @MuthukrishnanRajendran – Abhi

関連する問題