As title says, how can I do it? I looked over the internet and it seems that you just can't do it.. Anyone knows how can it be done?
I mean, I know how to execute my code when the user presses a button that closes the activity, but what about the hardware back button?
Thank you!
Override
onBackPressed()
:This will execute when the back button is used. If you want to run code even when the user navigates to another activity, or uses the home button, override
onPause()
Here is the code if you choose to do the onKeyDown/onKeyUp approach as ρяσѕρєя suggested.