yogi
yogi

Reputation: 1367

Determine number of uses of an app - Android

Is there a way to know how many time a user used the app? basicly i want to do some stuff after 3 uses, 5 uses etc... How can i hold this kind of information after it closed?

Upvotes: 0

Views: 64

Answers (3)

Lukas Knuth
Lukas Knuth

Reputation: 25755

How about saving the it somewhere? Like in a Database, a SharedPreference or an XML-File?

Upvotes: 0

Gregory
Gregory

Reputation: 4424

You could save that in the preferences. The following code opens the preferences, gets the number of times stored in it, and increments it.

SharedPreferences preferences = getPreferences(MODE_PRIVATE);
int times = preferences.getInt("openKey", 0);
preferences.edit().putInt("openKey", times+1).commit();

You can call this code in your activity's onCreate method.

Upvotes: 2

Asher
Asher

Reputation: 1867

You can use the SharedPreferences object to store and get any arbitrary information about your application.

Use the Context.getSharedPreferences method to get and instance of this object.

To edit use the edit method to get the editor. don't forget to call commit when you are done.

Important note: if the user uninstalls the application the preferences go away to (just something to keep in mind....)

Upvotes: 1

Related Questions