我正在制作一个启用\禁用键盘保护的应用程序,但它仅在第一次调用此活动时有效,之后它仍保持我第一次设置的状态。
static boolean k=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(k)
{
Log.d("unlock", "done");
KeyguardManager myKeyGuard1 = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock myLock1 = myKeyGuard1.newKeyguardLock(null);
myLock1.disableKeyguard();
k=false;
finish();
}
else{
Log.d("lock", "done");
KeyguardManager myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock myLock = myKeyGuard.newKeyguardLock(null);
myLock.reenableKeyguard();
k=true;
finish();
}
setContentView(R.layout.home);
}