应用程序启动数 [英] Application Launch Count

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

问题描述

我工作的一个应用程序,其中后说,5倍的应用程序被用户打开时,在第六届尝试应用程序应要求从用户的反馈。我试图用活动的OnStart OnResume ,但它不工作了,即使自从离开并重新进入活动的这些方法叫做。另外,作为用于Android的功能,我不能退出应用程序,这样我就可以找到它从被称为第一个活动。如何找到多少次,应用程序启动了?

I am working on an application, wherein after say 5 times the app is opened by a user, at 6th attempt the app should ask for feedback from user. I tried using Activity OnStart,OnResume, but its not working out since even after leaving and re-entering activity these methods are called. Also as per android functionality, I cannot quit app so that I can find it out from the first activity called. How do I find how many times the app was launched?

我希望这不是混乱。

修改

或者是有办法,其中我可以随时恢复从第一个活动我的应用程序(或欢迎页,例如),一旦用户presses家退出程序。

Alternatively is there a way, wherein I can always resume my app from the first activity( or welcome page for eg.), once user presses home to quit the app.

推荐答案

这其实很简单。使用共享preference或数据库。

This is actually quite simple. Using SharedPreference or the Database.

在OnCreate过程中添加1至numberofTimes柜台提交。

during OnCreate add 1 to the numberofTimes counter and commit.

OnCreate (Bundle bundle){
  mPref = getPreferences();
  int c = mPref.getInt("numRun",0);
  c++;
  mPref.edit().putInt("numRun",c).commit();
  //do other stuff...
}

OnCreate中被称为不管你启动应用程序,或者你恢复应用程序,但isFinishing()当且仅当且仅当用户返回true(或者)呼吁程序结束()(这是不被被破坏经理)

OnCreate is called regardless of you start the app or you resume the app, but isFinishing() returns true if and only iff the user (or you) called finish() on the app (and it was not being destroyed by the manager)

这样,你只有当你正在做新的开始递增。

This way you only increment when you are doing fresh start.

isFinishing()方法的内一个将OnPause方法来检查,看看是否该活动是正在完成()或只是被暂停。

the isFinishing() Method inside of a OnPause method to check to see if the activity is being finish() or just being paused.

@Override
protected void OnPause(){
  if(!isFinishing()){
    c = mPref.getInt("numRun",0);
    c--;
    mPref.edit().putInt("numRun",c).commit();
  }
  //Other pause stuff.
}

本涵盖了所有的场景:

1. user starts app/activity (+1)-> finishes app, exit with finish()
2. user starts app (+1) -> pause (-1) -> returns (+1)-> finish
3. user starts app (+1) -> pause (-1) -> android kills process (0) -> user returns to app (+1) -> user finish.

每一个场景,你只有每个活动的运行递增的时间运行一次计数器

every scenario you only increment the "times run" counter once per "run" of the activity

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

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