WakeLock 未释放且屏幕未关闭
我使用闹钟管理器来调用活动,并且使用 唤醒储物柜类< /a> onRecive() 唤醒手机,然后在 Activity 结束后调用 WakeLocker.release() 但屏幕仍然保持打开状态...
Receive.class:
public class MyScheduledReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
WakeLocker.acquire(context);
Activity.class
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
WakeLocker.release();
finish();
}
我已将其放在 onPause() 中, onStop() 无处不在...该东西不会释放,并且在我的应用程序关闭后屏幕不会自动关闭...
I've using alarm manager to call an activity and I'm using the wake locker class onRecive() to wake the phone and then calling WakeLocker.release() after the Activity is over but the screen still stays on...
Receive.class:
public class MyScheduledReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
WakeLocker.acquire(context);
Activity.class
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
WakeLocker.release();
finish();
}
I've put it in the onPause(), onStop() everywhere... the thing won't release and the screen won't turn off automatically after my app closes...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您请求许可
Make sure you request permission
您正在广播接收器中启动唤醒锁并在活动中停止它。
您正在引用唤醒锁的 2 个不同实例。您应该从 onreceive 开始活动,并在 onresume 中获取唤醒锁,然后仍然在 onpause 中释放(如果您希望在 onpause 中发生)。
你永远不应该启动任何应该在广播接收器中存在一段时间的东西,因为接收器会尽快被销毁。
You are starting the wakelock in a broadcastreceiver and stopping it in an activity.
You are referencing 2 different instances of a wakelock. You should start the activity from the onreceive and in onresume acquire the wake lock, then still release in the onpause if that is where you want it to happen.
You should never start anything that is supposed to be around for awhile within a broadcastreceiver, because the receiver is destroyed as soon as possible.
试试这个
Try this