views:

114

answers:

1

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?

A: 

You have to acquire PowerLock from here with SCREEN_DIM_WAKE_LOCK/PARTIAL_WAKE_LOCK flag.

Damian Kołakowski
so it's not possible to keep wi-fi on when screen is turned off entirely?
shuwo
No. It's possible. WiFi-Lock saves you from connection lost. You can use PARTIAL_WAKE_LOCK also. I think the problem is you didn't acquire CPU-Lock, so your code is not performed.
Damian Kołakowski