如何知道我的应用程序的活动计数? [英] How to know Activity Count of my application?

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

问题描述

我有我的应用程序的多个活动。 请考虑下面的案例...

I am having multiple activities in my application. Please consider following case...

活动A呼叫Acitivy B. B调用C.当用户presses备份C键生成通知,并涉及到B.现在再次preSS回来,所以会出现,然后再次返回键将终止为好,显示通知...现在,当用户presses通知图标活动Ç被加载....直到这部分行为是正确的....现在用户presses回来,我开始活性的使用我的code为C从通知加载。

Activity A calls Acitivy B. B calls C. When user presses back key C generates notification and comes to B. Now again press back, so A will be displayed and Again back key will terminate A as well and notification is displayed... Now, when user presses notification icon Activity C gets loaded....Till this part behavior is correct....Now user presses back, I start activity A using my code as C was loaded from Notification.

另一种情况 活动A呼叫Acitivy B. B调用C.当用户presses备份C键生成通知,并涉及到B.现在用户presses home键。然后,经过一段时间后选择通知图标,它会显示活动C.现在用户presses返回键,默认情况下它会显示活动B(我想)......但是我的code(如C来自加载通知)...即时显示活性的(N用户presses当时活动B被显示)。

Another case Activity A calls Acitivy B. B calls C. When user presses back key C generates notification and comes to B. Now user presses HOME KEY. Then after some time selects notification icon, it will display Activity C. Now user presses Back Key, By default it is displaying Activity B (which i want).... But my code(as C loaded from notification)... i m displaying activity A (n user presses back then Activity B is displayed).

我想知道我自己的应用程序活动计数,这样我才能避免执行我的code发起活动A(如果不是1)。

I want to know Activity Count of my own application, so that i can avoid execution of my code to launch Activity A (if it is not 1).

到目前为止,我已经做到了这一点通过以下code

So far i have done this using following code

ActivityManager actM = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> listm = actM.getRunningTasks(1);
int iNumActivity = listm.get(0).numActivities;

但这个code使用需要使用许可GET_TASKS ......我不舒服的这个,因为我不跟踪任何其他应用程序的数据/活动计数。

But usage of this code requires use permission GET_TASKS... I am not comfortable with this as i am not tracking any other application data/activity count.

如何解决这一问题? 有没有实现这一目标的任何其他方式?

How to fix this? Is there any other way to achieve this?

修改 如何知道自己的应用程序的活动计数?

EDIT How to know activity count of own application?

推荐答案

如果仅计算是issue..create在一个类中的静态计数变量表示常量。 或者可能有三个them..so每当你去一个特定的class..increment相应的静态公共变量。

If just count is the issue..create a static count variable in a class say Constants . or may be three of them..so whenever you go to a particular class..increment the corresponding static public variable.

编辑:您也可以将活动的次数在共享preferences

You can also keep the count of activities in the shared preferences.

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

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