title: How unlock and lock screen programatically in android
body: <p>I'm building a app which wakes and unlock's the phone on a event.</p>
  
  <p>This works fine..</p>
  
  <p>only when leaving the activity (or when a timer runs out..for when there's nobody around) i use reenableKeyguard() to restore the keylock to origenal state...</p>
  
  <p>but then it locks directly....</p>
  
  <p>i would like the normal behavour...so when the user exit's my app..there's no lock yet. but after 30 sec. of no activity phone goes to sleep and sets lock.</p>
  
  <p>how can i do this... thanks. </p>
  
  <p>Below is the code I have used for this:</p>
  
  <pre><code>    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
  
      getWindow().addFlags(
              LayoutParams.FLAG_DISMISS_KEYGUARD
              | LayoutParams.FLAG_SHOW_WHEN_LOCKED
              | LayoutParams.FLAG_TURN_SCREEN_ON
              | LayoutParams.FLAG_KEEP_SCREEN_ON
              );
  
  
  
      KeyguardManager manager = (KeyguardManager) getSystemService
      (Context.KEYGUARD_SERVICE);
      lock = manager.newKeyguardLock
      ("hh");
  
      lock.disableKeyguard();
    }
  
  
     protected void onStop() {
      // TODO Auto-generated method stub
      super.onStop();
      lock.reenableKeyguard();
  
  
  }
  </code></pre>
  
  <p>PLease let me know what are the changes I need to do in above code so it works nicely.</p>