title: Screen lock on button click
body: <p>I want to turn the android screen on button click,Now i had written a program for this in is not showing any errors also its not working..</p>
  
  <p>The code for this is..</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  Button powerOff;
  int amountOfTime =20*1000;
  Context context = this;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
  
      powerOff = (Button)findViewById(R.id.button1);
      powerOff.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
  
              // TODO Auto-generated method stub
              PowerManager.WakeLock mWLock;
               try {
                    System.out.println("Enter try Block");
  
                    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                    mWLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
                            PowerManager.ACQUIRE_CAUSES_WAKEUP |
                            PowerManager.ON_AFTER_RELEASE, "WakeLock");
                    mWLock.acquire();
               } catch(Exception e) {
                      Log.e("ScreenLock", "onStart()::acquire() failed " + e.toString());
               }
  
  
          }
      });
  
  
  }
  </code></pre>
  
  <p>I want to lock the screen and how can i do it???</p>