2

In my android application I use PROXIMITY_SCREEN_OFF_WAKE_LOCK WakeLock so that the screen is turned off when proximity sensor is activated.

The Android documentation says:

However, the device will not fall asleep while the screen has been turned off by the proximity sensor because it effectively counts as ongoing user activity.

But when the sensor is activated and the screen is off; the onPause event of my activity is called, and onResume is called again when the screen is on. Does it mean that the device go to sleep when the screen is off? any suggestion on how to prevent my activity from pausing when the screen is off?

ammcom
  • 992
  • 1
  • 7
  • 24
  • 1
    I'm having the same problem. On my nexus 5x it does NOT call onPause, which is expected. On a Galaxy S6 it DOESs call onPause. Suprise suprise. I wish all the samsung phones would blow up. – Tyler Pfaff Oct 13 '16 at 21:16
  • http://stackoverflow.com/questions/35318649/android-proximity-sensor-issue-only-in-samsung-devices – Tyler Pfaff Oct 13 '16 at 22:04
  • I used a combination of WakeLock and SensorManager Code to solve this – ammcom Oct 15 '16 at 12:59

1 Answers1

0

use PARTIAL_WAKE_LOCK, instead of PROXIMITY_SCREEN_OFF_WAKE_LOCK it will work for you. and acquire it in your activity oncreate() and release in onPause().

Shivanshu Verma
  • 609
  • 5
  • 19