简体   繁体   English

不推荐使用Android FULL_WAKE_LOCK,但不推荐使用PARTIAL_WAKE_LOCK

[英]Android FULL_WAKE_LOCK is deprecated but PARTIAL_WAKE_LOCK is not deprecated

Here i mentioned the code for waking up the screen. 在这里我提到了唤醒屏幕的代码。 i want the code is listen still the app is closed and the cpu is cleared and user can click the power button when ever my screen is unlock the app is sync like whatsapp. 我希望代码是监听仍然应用程序关闭和CPU清除,用户可以点击电源按钮,当我的屏幕解锁时,应用程序是同步像whatsapp。

    PowerManager pm =  (PowerManager)getSystemService(Context.POWER_SERVICE); 
    wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "whatever");
    super.onCreate(savedInstanceState);
    wl.acquire();

FULL_WAKE_LOCK is already deprecated and it's better to use the PARTIAL_WAKE_LOCK . FULL_WAKE_LOCK已被弃用,最好使用PARTIAL_WAKE_LOCK This is the standard way to do this, 这是执行此操作的标准方法,

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
Wakelock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
        "MyWakelockTag");
wakeLock.acquire();

For more way of implementation kindly visit the official link, 欲了解更多实施方式,请访问官方链接,

https://developer.android.com/training/scheduling/wakelock.html https://developer.android.com/training/scheduling/wakelock.html

Well you can consider an alternate, using JobScheduler for running background tasks while the app is still sleep for longer time thus preserving the battery. 那么你可以考虑使用JobScheduler来运行后台任务,同时应用程序仍然可以长时间睡眠,从而保留电池。 JobScheduler provides many methods to define job-execution conditions, therefore we can leverage that but it can be used for apps which are using Android 5.0 (API level 21) & above. JobScheduler提供了许多方法来定义作业执行条件,因此我们可以利用它,但它可以用于使用Android 5.0(API级别21)及以上的应用程序。

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

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