-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();
而不是存儲爲**計數器**,可以使用作爲**「[某種格式的日期] - 計數器」**在這你可以得到每一天 –
我該怎麼做。你可以告訴嗎? @MuthukrishnanRajendran – Abhi