简体   繁体   English

小米部分唤醒锁

[英]Partial wake lock on xiaomi

I am writing an android app in java which contains a stop watch counte r to record time spent on an activity.我正在 java 中编写一个android应用程序,其中包含一个秒表计数 r以记录在一项活动上花费的时间。 After the activity is finished, the user is supposed to stop the counter so that the counter reading can be recorded.活动结束后,用户应该停止计数器,以便记录计数器读数。

I have deployed a partial wake lock acquire on onCreate and release on onDestroy .我在onCreate上部署了部分唤醒锁获取并在onDestroy上释放。 I have also entered the required permission in the manifest file.我还在清单文件中输入了所需的权限。

The wake lock gets acquired successfully, but gets released when the app is running in background , that is, it's no longer active onResume .唤醒锁获取成功,但在后台运行时释放,即onResume不再处于活动状态。

When the app is running in background and screen is turned off , all the recent apps, including this one get wiped off the recent items screen after some time.当应用程序在后台运行并且屏幕关闭时,所有最近的应用程序,包括这个应用程序都会在一段时间后从最近的项目屏幕上擦除。 I am testing it on a Xiaomi Redmi Note 7 pro with MIUI 12.5.1 .我正在使用MIUI 12.5.1的 Xiaomi Redmi Note 7 pro 上对其进行测试。

Suggestions are welcome.欢迎提出建议。

The code used to deploy wake lock is:用于部署唤醒锁的代码是:

Context context = getApplicationContext();

PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);

final PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sachin:sachin");

wakeLock.acquire();

The permission entered in the manifest file:在清单文件中输入的权限:

uses-permission android:name="android.permission.WAKE_LOCK"

android:noHistory="false" android:excludeFromRecents="false"

A wakelock, in layman's terms, is just a way for an app to keep the CPU/screen/other things awake when the phone is idle in order to perform a specific background task.用外行的话来说,唤醒锁只是应用程序在手机空闲时保持 CPU/屏幕/其他事物唤醒以执行特定后台任务的一种方式。 Some apps do legitimately need wakelocks in order to function properly, but the problem comes when some applications hold wakelocks repeatedly, hold them for a long time without dropping them, or do excessive/unnecessary network and CPU tasks taking advantage of these wakelocks.一些应用程序确实需要唤醒锁才能正确执行 function,但是当一些应用程序反复持有唤醒锁、长时间持有唤醒锁而不丢弃它们,或者利用这些唤醒锁执行过多/不必要的网络和 CPU 任务时,就会出现问题。

Case in point: apps like Snapchat, Facebook, Messenger or other social media apps include misbehaving wakelocks.恰当的例子:Snapchat、Facebook、Messenger 或其他社交媒体应用程序等应用程序包括行为不端的唤醒锁。 This tutorial is simply a way to stop these wakelocks from happening again without uninstalling the app.本教程只是一种在不卸载应用程序的情况下阻止这些唤醒锁再次发生的方法。 If, however, you notice that the app stops functioning correctly after using this ADB command, you can change things back to the way they were by re-running the command and changing “ignore” to “allow”, or by simply uninstalling then re-installing the app again.但是,如果您注意到应用程序在使用此 ADB 命令后停止正常运行,您可以通过重新运行命令并将“忽略”更改为“允许”,或者通过简单地卸载然后重新- 再次安装应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM