计数应用程序使用Android中应用程序、Android

2023-09-07 13:31:37 作者:你会腻我何必

谁能帮我决定如何指望有多少次的应用程序已经在Android中使用?

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

推荐答案

只是,宣布:

    private SharedPreferences prefs;
    private SharedPreferences.Editor editor;
    private int appOpened;

在初始化的onCreate(...)

prefs = getPreferences(Context.MODE_PRIVATE);
editor = prefs.edit();

计数,无论你想(在任何地方的onCreate()或你的愿望的任何方法):

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();

然后使用 appOpened 变量做你的任务。

干杯!