Android的,是否唤醒功能被激活时,在申请的孔? [英] Android, Does Wake Lock is active when In the hole of application?

查看:87
本文介绍了Android的,是否唤醒功能被激活时,在申请的孔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的一些活动。在主要的活动我已经定义了唤醒锁:

I have some activities in my application. In main activity I have defined the wake lock:

PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");

和发布它的onPause()方法。我的问题是,它是活跃在整个应用程序的?或者我是否需要复制/粘贴在每一个我有活动呢?

and released it in onPause() method. My question is, is it active in the whole of application? or Do I need to copy/paste it in each activity that I have?

感谢

推荐答案

只要WakeLock被收购,那么久之后持有锁。相关是你WakeLock对象的生命周期。如果WakeLock没有更多的使用和同时还具有锁,它的垃圾收集过程中释放的真实是GC'd(在finalize()方法)。

As long as WakeLock is acquired, so long wake lock is held. Related is lifetime of your WakeLock object. And if WakeLock is no more used and it is GC'd while still having lock, it's released during garbage collection (in finalize() method).

所以,你醒来的锁是活动获取的()和release()。你必须确保从需要的活动需要时您code调用这些函数。

So your wake lock is active between acquire() and release(). You must make sure that your code calls these functions when needed from desired activities.

如果您在应用程序在全球范围要WakeLock,延长android.app.Application,清单中指定,并在应用层面管理唤醒锁。

If you want WakeLock globally in your application, extend android.app.Application, specify it in manifest, and manage wake lock on application level.

这篇关于Android的,是否唤醒功能被激活时,在申请的孔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆