我试图在肖像时关闭 proximitywakelock ,在使用此代码时横向关闭,但它始终保持活动状态:
//in onCreate() of my Activity
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mProximityWakeLock = pm.newWakeLock(32, ""); // proximity_wake_lock=32
mProximityWakeLock.setReferenceCounted(false);
if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "non landascape", Toast.LENGTH_SHORT).show();
if (!mProximityWakeLock.isHeld()) {
mProximityWakeLock.acquire();
Toast.makeText(this, "acquired", Toast.LENGTH_SHORT).show();
}
if (!mProximityWakeLock.isHeld())
Toast.makeText(this, "not held", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, " held", Toast.LENGTH_SHORT).show();
} else {
if (!mProximityWakeLock.isHeld())
Toast.makeText(this, "not held", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, " held", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "landascape", Toast.LENGTH_SHORT).show();
if (mProximityWakeLock.isHeld()) {
mProximityWakeLock.release();
Toast.makeText(this, "released", Toast.LENGTH_SHORT).show();
}
}
看起来它在景观上从未举行过......
isHeld()
如何实际运作?
代码有什么问题?
答案 0 :(得分:0)
我看起来每次旋转屏幕时都会创建一个新的唤醒锁,并且不会保留新的唤醒锁。
如果您查看日志,可能会看到有关泄漏唤醒锁的事情。