I work on Android Studio while using actual device for ADB using ADB over tcp/ip through command prompt (no additional software). But, this new device gets offline the moment screen turns off. I've tried turning off everything related to Battery Optimization or Wifi. Although, there's no such specific setting to let the Wifi awake after device sleeps like my old phone Huawei.

I'd also posted this over the official forum of Realme about a week ago but no one has replied so far. Link - Wifi gets turned off after screen lock - ADB issues.

So, Device's status in ADB devices goes to offline the very moment screen locks and then I've to do the process of ADB Wifi all over again and I don't want to use cable all the time because it affects battery through that 0.5/0.9 mA slow charging through motherboard. It is already slow enough that battery gets discharged even after continuous charging. I use ADB Wifi for more than 14 hours per day hence I need a stable solution.

So, my question is how to keep the device's Wifi on even after screen lock? I know it's device specific because of the custom changes to the ROM but I really need something.

  • adb disconnection might be related to a lock screen (adb disabled for security reasons). Alternatively is your device rooted? If yes you can disable charging on most devices so you could connect your device via USB without charging.
    – Robert
    Commented Sep 26, 2020 at 11:03

3 Answers 3


I have a windows batch file that just calls adb and touches the top left pixel of the screen once every 2 seconds. Leave that running in another command prompt window and your device will never sleep. One could do this with wakelocks and proper code and all that, but this method works (as long as there's not an active UI element at position 1,1, which there isn't usually. One could send a mouse-motion or something I guess but this works and is v.simple.

@echo off
adb shell input tap 1 1
powershell -nop -c "& {sleep 2}"
echo | set /p="."
goto :start

I run the device farm in our company based on ADB wifi and I had similar problem. I ended up with creating an app to keep wake-lock all the time to prevent device sleep (it has to have foreground service, otherwise it gets killed too, and it has to have turned off battery optimization for the same reason). Now I am online nearly all the time.

  • Have you published your app or its source code? Commented Jun 11, 2021 at 0:08
  • Sorry, I cannot do this, as it was made during my work hours and hence it's property of the company I am employed in. But the app is pretty simple and shouldn't be hard for android developer to make his own. Commented Jun 13, 2021 at 19:15

It's a bug in the rom in some kinds of android devices, apparently. This fixed it for me:

Link: https://github.com/Genymobile/scrcpy/issues/1382

Here's what you have to do:
Go to Usb preferences in developer options, and change it from "data transfer" or anything else to "no data transfer". Tell me if this fixed it for you! Sending this here for any onlooker.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .