title: How to lock/unlock phone programmatically : Android
body: <p>In my application, I need to lock and unlock phone. I searched for it, I found many answers, I tried them but no one is working.</p>
  
  <p>I need to unlock phone on <code>onCreate()</code> and lock phone again while I'm finishing my activity.</p>
  
  <p>Do you guys know any method to do the same?</p>
  
  <p>Thanks friends.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Some links, that I have tried are:</p>
  
  <p><a href="https://stackoverflow.com/questions/3793221/how-my-app-can-unlock-screen-programatically">How to display Activity when the screen is locked?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12723185/android-screen-lock-unlock-programatically">Android screen lock/ unlock programmatically</a></p>
  
  <p><a href="https://groups.google.com/forum/#!topic/android-developers/BOLjJTMO4zE" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/android-developers/BOLjJTMO4zE</a></p>
  
  <p>In my application I'm scheduling a task using <code>AlarmManager</code> and then enabling the phone lock. My activity is getting started on scheduled time but it not unlocking my phone. when I'm unlocking my phone manually running activity is getting appeared</p>