使用Jelly Bean,AppCompat API和ActionBarActivity按Home键最小化应用程序时,使用密码重新打开

时间:2014-02-15 06:08:47

标签: android android-intent broadcastreceiver action android-actionbar-compat

我在我的应用中添加了密码功能。它工作正常。如果创建了密码,我已经集成并检查启动画面然后询问密码其他主要活动,它工作正常。   但是,如果我在任何活动,然后最小化应用程序并重新打开应用程序然后它应该询问密码然后应用程序正常的主页键功能意味着活动保持相同,最小化,如主键应用程序最小化和重新打开,它工作。

我正在使用AppCompact API和ActionBarActivity。

如果错误,我需要适当的解决方案。我试图用onStart方法和onKeyDown()或onKeyUp()实现

Method try : 1
//------------------------------------------

        @Override
        protected void onStart() {
            // TODO Auto-generated method stub
            super.onStart();
            if (isPasscode) {
                isPasscode = false;
                if (AppPreferences.getInstance().isPasscodeSaved()) {
                    Intent intent = new Intent(this, PasscodeActivity.class);
                    intent.putExtra(GlobalConst.VERIFY_PASSCODE, true);
                    startActivityForResult(intent,GlobalConst.REQUEST_PASSCODE);
                }
            }
        }  

//--------------------------------------
// Not calling on home key pressed
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if(keyCode == KeyEvent.KEYCODE_HOME){
            Log.d("Test", "Home button pressed!");
          // Not calling on home key pressed
            isPasscode = true;  // If it will true on home pressed then I will implement all the activity but not happening .
        }
        return super.onKeyDown(keyCode, event);
    }

//----------------------------------------------------
//---------------------------------------------------

Method try : 2: instead of onKeyDown , I have try to use onUserLeaveHint() method , It work but not properly . It call on home key pressed but call many time  after start method , Onactivity result method, activity refresh many time and also it property is interrupted with in coming call.

//--------------------------------------
        @Override
    protected void onUserLeaveHint() {
        // TODO Auto-generated method stub
        super.onUserLeaveHint();
        if (!isPasscode) {
            isPasscode = true;   
        }
    } 
//---------------------------------------

0 个答案:

没有答案