1

I have been trying to fetch Back Key Press in Service, but I am having no result. In Activity there is function onKeyDown() which recognises various key events. Is there a way in Service to determine if Back Key was pressed.

2 Answers 2

1

A Service is not intended to work directly with user actions, so no. But if this Service is running at the same time as your Activity, then the Activity could notify the Service that the back key has been pressed.

4
  • 1
    No need to be "bound", you can also fire an intent to a started service.
    – Snicolas
    Dec 12, 2012 at 7:15
  • I dont want to fetch the back key on my activity, I just want that my service should be running in background, and whenever I press back key anytime not necessarily in my activity, It should pop up a Toast Dec 12, 2012 at 7:15
  • @RohitJindal A Service itself cannot listen for key presses.
    – Sam
    Dec 12, 2012 at 7:17
  • Accessibility Service is a option which can handle Click, Focus events anywhere in the mobile. Is there any other attribute of Accessibiltiy Service which can gather Back Key Events Dec 12, 2012 at 7:20
0

An option could have been to register a broadcast receiver for an action matching the home key press but I can't find any.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.