2

How can I invoke arbitrary code in Android when the screen of the device is turned off? Is there a callback of some sort?

avalancha
  • 1,457
  • 1
  • 22
  • 41
user5819
  • 534
  • 4
  • 11

2 Answers2

0

The system will broadcast a message when the screen turns on and off. Here is the detailed answer https://stackoverflow.com/a/4208538/1581921

Community
  • 1
  • 1
mrgenco
  • 348
  • 2
  • 9
  • 27
0

Build a BroadcastReceiver on the on/off screen. The Android system broadcasts a message when certain things happen ( like the screen going on/off , battery changes etc. ) With the BroadCastReceiver you will tell your app how to react when the screen will go off.

BMU
  • 429
  • 2
  • 9