计数应用程序使用Android中 [英] Counting application usage in Android

查看:110
本文介绍了计数应用程序使用Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我决定如何指望有多少次的应用程序已经在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 变量做你的任务。

干杯!

这篇关于计数应用程序使用Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆