Reputation: 4037
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.
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?
Upvotes: 3
Views: 2698
Reputation: 29722
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.
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.
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.
I was exploring this exact topic a few months ago (end 2013), and looking at production launcher code really helped.
Upvotes: 1