确定何时单击应用程序图标以在 android 中启动应用程序
android 有什么方法可以确定用户何时单击应用程序图标来启动应用程序?我的意思是说用户正在使用我的应用程序。然后他按下主页键,应用程序进入后台。一段时间后,他再次单击应用程序图标。我的问题是我会收到回电吗?
Is there any way in android to determine when the user clicked the app icon to launch the app ? I mean say a user was using my app. Then he presses the home key as a result of which the app goes to the background. After sometime he clicks the app icon again. My question is do I get a call-back for this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
仅供告知,我在启动器活动中使用了标志
android:clearTaskOnLaunch="true"
。结果,它的 onResume 方法被调用,我可以识别出启动器图标被单击Just to inform, I used the flag
android:clearTaskOnLaunch="true"
in my launcher activity. As a result, its onResume method was called and I could identify that the launcher icon was clicked如果应用程序已在堆栈中,它将调用 onResume() 方法。如果应用程序不在堆栈中,那么它将调用 onCreate() 方法。
此机制基于为活动指定的启动模式。
It will call the onResume() method if the app is already in the stack. And if the app not in the stack then it will call the onCreate() method.
This mechanism is based on the launchMode specified for the activity.
请阅读 http://developer.android.com/reference/android/ app/Activity.html#ActivityLifecycle
您的应用程序有多少个 Activity,您将获得最后一个打开的 Activity 的回调
onResume()
。please read http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
How many activities your application has, you will get a callback
onResume()
for the last open activity.如果应用程序来自后台,您可以通过获取意图标志来检查它,
如果您的应用程序来自后台,则该标志为真。如果您点击应用程序图标将其打开,则上述逻辑将不成立。
If an app comes from the background, you can check it by getting intent flags
it will be true if your app comes from the background. If you click on the app icon to open it, the above logic will not be true.