3

Wi-Fi 経由で着信要求を継続的にリッスンする必要があるアプリケーションがあります。バックグラウンドで実行されるサービスがこの仕事をします。ただし、このサービスは、画面がオフになるとしばらくするとスリープ状態になります。

私が検索した解決策は、AlarmManagerを使用してそれを目覚めさせることです。しかし、これはデバイスのバッテリーを消耗させると言われています。それで、これを行う別の方法はありますか?

たとえば、Whatsapp や Skype などのアプリは何をしますか? 彼らはあまりにも多くのバッテリーを殺しているようには見えませんが、継続的にサービスを実行していますか?

また、AlarmManager が唯一の方法である場合、誰かがチュートリアルや例を共有してくれると本当に親切です。

4

2 に答える 2

2

The solution from what I have searched is to use AlarmManager to keep it awake

That will not help. Once the device falls asleep, your socket connection will be terminated. You would need to use a partial WakeLock plus a WifiLock to keep the device powered on continuously.

But it is said that this will drain the battery of the device.

The WakeLock and WifiLock will definitely drain the battery.

So, is there another way to do this?

Not if you need to use WiFi.

For eg, what do apps like Whatsapp and Skype do?

They do not use WiFi when the device wants to go to sleep. Once the WiFi radio powers down, they use mobile data, so no WifiLock is needed. For mobile data, incoming packets will wake up the device, so you only need a WakeLock while you are actually doing work, rather than constantly.

The best answer is to switch to use C2DM, though.

于 2012-04-19T17:38:05.757 に答える
2

実際には、スリープ状態になるのはサービスではなく、デバイス上の WiFi ユニットです。HTC (またはおそらくすべての Android デバイス) などのメーカーは、デバイスにこの種の動作を実装しており、一定時間画面がオフになった後に WiFi ユニットがスタンバイになります。これにより、デバイスが使用されていないときにバッテリーを節約できます。

于 2012-04-19T17:38:30.763 に答える