jehan
jehan

Reputation: 267

Counting application usage in Android

Can anyone help me determine how to count how many times an application has been used in Android?

Upvotes: 3

Views: 2007

Answers (4)

Punith K
Punith K

Reputation: 666

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!

Upvotes: 1

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

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

Upvotes: 0

karnok
karnok

Reputation: 1202

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...

Upvotes: 0

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

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.

Upvotes: 1

Related Questions