伯爵在Android手机与屏幕的互动 [英] Count interactions with screen in Android phone

查看:135
本文介绍了伯爵在Android手机与屏幕的互动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid和发展其在后台运行的服务来收集用户活动的应用程序。到现在我的应用程序能够获得有关用户使用的其他应用程序TIME_START,TIME_END和名称的信息。

I am new in Android and is developing an app which runs in background as service to collect user activity. till now my app is able to get information about Time_Start, Time_End and Name of other app used by user.

我想提高我的应用程序,以便能够计算有多少相互作用(比如用户敲击,触摸,...),使用户在使用其他应用程序。任何一个可以提供有关这个问题的一些建议?就在这样做,我会用我自己做的所有细节。

I want to improve my app to be able to count how many interactions(like user tap, touch,...) user make while using other app. Can any one give some advices about this issue? Just the way to do and I'll do all details by myself.

谢谢!

推荐答案

要做到这一点,最好的办法是实施监听的用户交互的类型,你想指望。在你的活动一个全局变量。与用户进行交互时,都会添加一个到它。

The best way to do this is to implement Listeners for the types of user interactions you would like to count. Have a global variable in your activity. Every time the user interacts, add one to it.

如果你想保持计数整个应用程序,你可以保存在共享preferences一个变量,并在每次活动结束后,添加您的活动的全局变量计数你有店共享$ P值$ pferences。或者,你可以只编辑已存储在共享preferences马上对每一个用户交互蝙蝠的价值。只需记住将共享preferences的值当您第一次启动应用程序,存储在共享preferences值即使在应用程序被关闭的存储,除非你专门删除它们,或清除共享preferences。

If you want to keep count across the entire app, you could save a variable in SharedPreferences, and at the end of each activity, add your activity's global variable count to the value you have store in shared preferences. Or, you could just edit the value you have stored in SharedPreferences right off the bat on every user interaction. Just remember to reset the value of the SharedPreferences when you first start the application, as values stored in SharedPreferences are stored even after the app is closed unless you specifically remove them, or clear the SharedPreferences.

另一种方式,你可以保持数是使用全局静态变量,它是所有其他活动进行访问。你将能够从其他的活动增加它通过这种方式。这被普遍认为虽然不良做法,所以我反对这项建议。

Another way you could keep count is by using a global static variable that is accessible from all other activities. This way you would be able to increment it from other activities. This is generally considered bad practices though, so I advise against this.

本文档共享preferences是在这里:

The documentation for SharedPreferences is here:

http://developer.android.com/reference/android/content/SharedPreferences.html

该文档实现输入事件监听器是在这里:

The documentation for implementing input event Listeners is here:

http://developer.android.com/guide/topics/ui/ui-events.html

希望这有助于!

Hope this helped!

这篇关于伯爵在Android手机与屏幕的互动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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