How to find if phone is in standby mode? (Screen is off, power button pressed)

android, screen, state

Solution

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();

Problem

As title says, i need to get this information regarding the screen state. I think stanby is the correct state i mean, that is when you press the power button and the screen turn off completely. But how to detect this? Tnx in advance for your help. SOLVED: I managed to solve the problem i was having: the code was right, but the thread was stopping executing when in stanby mode; that's because i was having the wrong feeling that the code was wrong. Solved simply by using a wake lock, that ensure the cpu will be active even when in stanby mode: ``` PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag"); wl.acquire(); ..CPU will stay on during this section.. wl.release(); ```

Original source

Related problems