可靠的方式从家里/桌面检测应用程序启动? [英] Reliable way to detect application launch from home / desktop?

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

问题描述

我希望每个用户打开应用程序时进行检测,在回家/桌面图标点击。目前似乎没有做一个直接的方式。发现了一些解决方法,但似乎没有成为真正可靠的。

I want to detect each time the user opens the app, by tap on home / desktop icon. There seem not to be a straight forward way to do it. Found a few workarounds but nothing seems to be really reliable.

样,扩展应用对象和使用方法的onCreate(),但这不是我所需要的,因为当用户在应用程序的图标水龙头(可以从后台只是把它并不总是叫物联网,推出没有按'吨一定重新创建应用程序),并且还应用可以销毁和运行时创建。然后Application.onCreate()也将被调用。

Things like, extend application object and use method "onCreate()", but this is not what I need because it's not called always when the user taps on the app's icon (can be just brought from the background, launching doesn't necessarily recreate the application), and also the application may be destroyed and recreated while running. Then Application.onCreate() will also be called.

有战争还涉及广播接收器和检查意向标志,但一切的一些方法似乎也不太可靠?

There war also some approaches involving BroadcastReceiver and checking intent flags but everything seems to be also not quite reliable?

我需要这个,因为我想跟踪与谷歌分析,当用户打开应用程序。

I need this because I want to track with Google Analytics, when the user opens the app.

感谢

推荐答案

尝试寻找到Android应用程序的生命周期。

Try to look into "android application lifecycle".

onResume 启动每次启动活动时间

But onResume is launched every time you start your activity

否则试试:在onStart 这就是所谓的每一个应用程序已经发送到后台的时间。它确实状态,所以在开发者文档

Else try : onStart which is called every time your application has been sent to "background". It really does state so in the developer docs.

这篇关于可靠的方式从家里/桌面检测应用程序启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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