1

因此,我有一项活动会越过我的锁屏。但是当我退出它时,它会破坏我的锁屏。好的,不是字面意思......但我无法再次成功锁定我的手机。我必须重新启动它。我觉得我只是忘记在我的 onDestroy 中放一些东西 - 就像我必须在完成锁屏后重新评价它。同上。问题是什么?

锁屏活动:

@Override
public void onCreate(Bundle icicle){
    super.onCreate(icicle);
    setContentView(R.layout.lockscreen);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);//gotta get it to open on lock screen

    ImageView iv = (ImageView)findViewById(R.id.Background);
    //iv.getBackground().setAlpha(50);

    Button close = (Button)findViewById(R.id.Close);
    close.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
    final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("IN");
    kl.disableKeyguard();

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wl=pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "My_App");
    wl.acquire();

    /*Builder adb = new AlertDialog.Builder(this);
    adb.setMessage("Testing");
    adb.setCancelable(false);
    adb.setNeutralButton("Close",new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which) {
            kl.reenableKeyguard();
        }
    });
    AlertDialog ad = adb.create();
    ad.show();*/

    wl.release();
}

如您所见,我刚刚完成了活动。我是否忘记在销毁上做某事?

谢谢

4

1 回答 1

0

哇...就这么简单:

kl.reenableKeyguard();

把这是取消它的按钮:

@Override
        public void onClick(View v) {
            kl.reenableKeyguard();
            finish();
        }

仍在尝试弄清楚如何通过后退按钮使其无法取消....

编辑:

看来我不需要KL的决赛。所以你会这样做:

KeyguardManager.KeyguardLock kl;

@Override
public void onDestroy(){
    kl.reenableKeyguard();
    super.onDestroy();
}

@Override
public void onCreate(Bundle icicle){
    super.onCreate(icicle);
    setContentView(R.layout.lockscreen);
    KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
    kl = km.newKeyguardLock("IN");
    kl.disableKeyguard();
}

仅适用于将来需要此功能的任何人。

于 2012-03-11T03:23:45.550 回答