Can anyone help me determine how to count how many times an application has been used in Android?
Just, declare:
private SharedPreferences prefs;
private SharedPreferences.Editor editor;
private int appOpened;
Initialize in onCreate(...)
:
prefs = getPreferences(Context.MODE_PRIVATE);
editor = prefs.edit();
count wherever you want (any where in onCreate()
or any Method of your wish):
appOpened = prefs.getInt("counter", 0);
appOpened++;
editor.putInt("counter", appOpened);
editor.commit();
Then you use appOpened
variable to do your task.
Cheers!