I'm developing an app in which i need the TCP connection to stay alive. I've implemented a kind of ping/pong system to do this. It works perfectly when the screen is on, but when it goes of the phone stops responding to the pings after a while. I've created a Wi-Fi wake lock but i'm still experiencing still the same problem..
This is my code:
private static WifiManager wm = getSystemService(this.WIFI_SERVICE);
private static WifiLock wl = null;
public static void lock(){
    wl = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , App.TAG);
    if(!wl.isHeld()){
        wl.acquire();
    }
}
public static void unlock(){
    if(wl != null){
        if(wl.isHeld()){
            wl.release();
        }
    }
}
Any ideas?
You have to acquire PowerLock from here with SCREEN_DIM_WAKE_LOCK/PARTIAL_WAKE_LOCK flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With