gpt4 book ai didi

android - 当设备屏幕被锁定时,UDP/RTCP 数据包未到达设备/应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:01 24 4
gpt4 key购买 nike

我的 VOIP Android 应用程序有 C/Native 库,它执行登录/注销等所有业务逻辑。

问题是当设备屏幕被锁定时,应用程序(c 代码)无法从服务器接收任何数据包。我用 Wireshark 验证了这一点。看起来 CPU 没有运行。

我能够在我的应用程序 INIT 上执行以下操作来解决问题。

WakeLock mWakeLock =  null;
PowerManager pm = (PowerManager) cxt.getSystemService(Context.POWER_SERVICE);
if(mPartialWakeLock == null){
// lock used to keep the processor awake.
mPartialWakeLock = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ON_AFTER_RELEASE, TAG);
mPartialWakeLock.acquire;
}

但这样做会耗尽我的电池。

为什么请求没有到达我的应用程序?当 Screen LOCKED 并接收来自服务器的请求时,如何让设备 CPU 一直运行?

注意:已编辑使用的设备:Samsung Rugby Smart i847操作系统:安卓操作系统,v2.3.6 (Gingerbread.UCLA4)

该应用程序可在 Galaxy s2 上运行。(是否因为它的双核处理器和 CPU 在屏幕锁定上?)SKYPE和VIBER是如何将WRT设计成休眠模式的??

最佳答案

你考虑过使用 service 吗? ?

Service is providing a facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). By starting it, system will schedule work for the service, to be run until the service or someone else explicitly stop it.

我想这会有所帮助..干杯

编辑:Oki,你之前没有提到服务..我仍然不确定你是否有两个问题(耗尽电池和不接收数据)或者只是一个你接收数据的问题..?

考虑到耗尽电池电量,您可以尝试使用 WAKE_LOCK 的不同标志.

我注意到的重要事情是您没有按照链接 WAKE_LOCK 上的建议使用 mPartialWakeLock.release() 释放 锁页:

Device battery life will be significantly affected by the use of this API. Do not acquire WakeLocks unless you really need them, use the minimum levels possible, and be sure to release it as soon as you can.

此外,根据其他一些posts ,电池消耗速度取决于您在服务中所做的工作和效率,因此如果不查看更多代码,我们将无法提供帮助.. :S

顺便说一句.. 恕我直言,如果你只是等待来电并且你一直保持 WAKE_LOCK,那可能是电池高耗电的原因.. 想想你需要什么,如果你不这样做,尽量减少资源的使用不需要它们..例如考虑WIFI_LOCK,并尽快释放WAKE_LOCK..

关于android - 当设备屏幕被锁定时,UDP/RTCP 数据包未到达设备/应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11298039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com