0

i have a chat application.my code has a thread which manages internet connection. but after some minutes my thread goes sleep. I know i should use WakeLock to wake CPU and my thread. but when i use below code , battery usage goes up.

if (mWakeLock == null) {
                        mWakeLock = pm.newWakeLock(
                                PowerManager.PARTIAL_WAKE_LOCK,
                                "NewOnlineSignalingPowerManagerTag");
                    }
                    if (mWifiLock == null) {
                        mWifiLock = wm.createWifiLock(
                                WifiManager.WIFI_MODE_FULL,
                                "NewOnlineSignalingWifiManagerTag");
                    }
                    if (!mWakeLock.isHeld()) {
                        logging.l("mWakeLock.acquire()");
                        mWakeLock.acquire();
                    }
                    if (!mWifiLock.isHeld()) {
                        logging.l("mWifiLock.acquire()");
                        mWifiLock.acquire();
                    }

can you prefer me a better way?

4

1 回答 1

0

为什么你必须管理互联网连接?你不必。使用安卓服务,不会出现线程问题,也不会出现睡眠问题。

于 2012-11-27T06:02:42.983 回答