Android的检测通过HOME或BACK键恢复活动 [英] Android detect activity resume via HOME or BACK keys

查看:192
本文介绍了Android的检测通过HOME或BACK键恢复活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了我的申请家庭应用,所以,当你$ P $ HOME PSS按钮,您将被重定向到我的应用程序。从我的应用程序,您可以打开其他应用程序,如浏览器,然后由pressing BACK或HOME键返回到我的应用程序无论是。
现在的问题是,我需要知道什么时候使用的家庭用户的回报,并使用BACK键时。
我试图打印意向的信息,但是它似乎是在这两种情况下是相同的。

I have made my application HOME application, so that when you press HOME button, you are redirected to my application. From my application you can open other applications like browser and then return to my application either by pressing BACK or HOME keys. The problem now is that I need to know when user returns using HOME and when using BACK key. I tried printing Intent information, but it appears to be the same in both scenarios.

使用getIntent在onResume修改我在检查意图()。覆盖onNewIntent方法后,我现在得到一个不同的目的有在使用HOME键用户返回,但这种方法不被调用时,后面是pressed。它是安全的假设,即如果与android.intent.category.HOME onNewIntent被调用,那么用户使用HOME键返回,否则返回使用返回按钮?

EDIT I was checking intent in onResume using getIntent(). After overriding onNewIntent method I now get a different intent there when user returns using HOME button, but this method is not called when BACK is pressed. Is it safe to assume, that if onNewIntent with android.intent.category.HOME is called, then user returned using HOME button and otherwise returned using BACK button?

推荐答案

onNewIntent()应用程序运行时被触发,并收到另一个意图推出。这就是为什么你看到它的时候家是pressed。

onNewIntent() is fired when an app is running, and receives another intent to be launched. That is why you are seeing it when HOME is pressed.

在背面则是pressed,您的应用程序不会收到意图。所有这一切发生的情况是在你之上的应用程序被删除。所以,你的应用程序从后面出现堆栈使用只用 onResume()被调用。

When BACK is pressed, your app is not going to receive an intent. All that happens is that the apps on top of yours are removed. So your app appears from the back stack with only onResume() being called.

所以这就是你如何分辨。

So that is how you can tell.

有关的兴趣,你可以看一下源$ C ​​$ C对于上了年纪发射线上,你会看到 onNewIntent()用于重新中心主页也就是说,它可以帮助你看看HOME键已经pssed两次$ p $上发射视图。

For interest, you can look at the source code for the older launchers online, and you will see that onNewIntent() is used to re-centre the launcher view on the main page i.e. it can help you to see if the HOME key has been pressed twice.

我是几个月前探索这个话题确切(2013年年底),看着生产启动code真的帮了。

I was exploring this exact topic a few months ago (end 2013), and looking at production launcher code really helped.

这篇关于Android的检测通过HOME或BACK键恢复活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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