1

Suppose I have something like an alarm activity which launches the alarm through the lock screen, accomplished via

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Now, from here I could press the back button to kill the activity, but I also want a press of the lock button to silence the alarm. How would I go about creating a handler for presses of the lock screen button?

damonkashu
  • 1,813
  • 5
  • 19
  • 25

1 Answers1

2

Listen to this broadcast intent

ACTION_SCREEN_OFF

You can switch off your alarm when you get this intent

Prashast
  • 5,645
  • 3
  • 30
  • 31
  • 2
    could you elaborate a bit more? – damonkashu Nov 12 '10 at 21:04
  • @DanielQuach: Take a look at: http://stackoverflow.com/questions/11346958/listening-for-action-screen-off-on-android - Here the response give a code to do that – Renato Lochetti Nov 14 '12 at 11:20
  • That only works if the app is activity. You cannot listen for ACTION_SCREEN_OFF after your app has moved to the background. Reason being you must unregister the receiver in e.g onStop. – H.Rabiee Jul 28 '14 at 17:39