Counting application usage in Android

前端 未结 4 1512
南笙
南笙 2021-01-20 13:18

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

相关标签:
4条回答
  • 2021-01-20 13:51

    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!

    0 讨论(0)
  • 2021-01-20 14:00

    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.

    0 讨论(0)
  • 2021-01-20 14:04

    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

    0 讨论(0)
  • 2021-01-20 14:12

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

    0 讨论(0)
提交回复
热议问题