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!
Write to a SharedPreferance onCreate. It won't be a very accurate count since onCreate is called at times other than only application start-up, but it'll be a reasonably good figure.
If you offer more details as to why you're doing this, you may get a more detailed answer.
by using Flurry we can do this.
The Flurry Android Analytics Agent allows you to track the usage and behavior of your Android application on users' phones for viewing in the Flurry Analytics system
You could have a file which stores one number, not on the SD card but locally for your app. Then open this and increment the number in your onCreate method. You can also keep track of when they do other things but don't actually close it with onPause and onResume... There might be another way to save data without explicitly creating a file...