• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Identifying back button press

Hi all,

Identifying a back button pressed event is veru simple. But I want to do it in different way.
Say my application is installed on a device. Currently user is doing some stuff in Alarm Clock. But now when I press back button or any other button it should no back to the home screen or anywhere but it should open my application. WidgetLocker is the application which is doing the same thing. It uses power button to perform the task. Whenever you press power button from anywhere in the phone it throws to its own customized lock screen.

I want to perform the similar task using some buttons. Can anyone guide me?
 
Then it sounds like you should use a Service to get key event, and start your app from that service.
 
If there is a broadcast for buttons, than that of course is the best way. Did not know there were any for buttons.
 
Was also only a wild guess from my side...

Looks like there are no broadcast actions for specific buttons, only activity intents...

Dunno what to try then, except from a Service listening in on the intents somehow. More on which intents to possibly use here:

Intent | Android Developers
 
Yes, Services or Broadcast receiver is the only way.
But there is no broadcast receiver for back button.

Can any one suggest how to bind key events with services.I want to run particular service which will start on press of back button.

What to do in this case. and what Intent I should use is the question.
 
For you service to be able to do anything as the back button is pressed, you'll need to have it running all the time. Only a broadcast receiver can "wake up" on an event like that.

So you'll need the service running and listening in on the back button somehow. And then trigger whatever reaction you want...
 
For you service to be able to do anything as the back button is pressed, you'll need to have it running all the time. Only a broadcast receiver can "wake up" on an event like that.

So you'll need the service running and listening in on the back button somehow. And then trigger whatever reaction you want...

Exactly.. But I think there is no broadcast receiver which can listen that Back Button is pressed.There are receivers for Power button, Camera Button,Search Button etc..

How to do this with services I have no idea.
Can anyone mention few steps to start the same with services.
And first of all is this possible?
 
Use the debug mode in eclipse with usb debug on your phone.
If you touch the back button it will send an event and it should be visible in the debugger because it shows evrything the phone is doing.

Hope this will work for you
 
Back
Top Bottom