title: Android turn on the screen
body: <p>I making the application where an activity launch is scheduled by AlarmManager. I would like to appear even if the screen is turned off and device is locked.</p>
  
  <p>To achive this a set the Window flags</p>
  
  <pre><code>final Window win = getWindow();
  win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
          | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
          | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
          | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
  </code></pre>
  
  <p>And try to obtain lock for the screen</p>
  
  <pre><code>if(_lock == null)
  {
      PowerManager pm = (PowerManager)App.getAppContext()
              .getSystemService(Context.POWER_SERVICE);
  
      _lock = pm.newWakeLock(
              PowerManager.FULL_WAKE_LOCK, "ScreenOn");
      _lock.acquire();
  }
  </code></pre>
  
  <p>The _lock is PowerManager.WakeLock which is released in onPause</p>
  
  <pre><code>protected void onPause()
  {
       if(_lock != null)
       {
            _lock.release();
       }
  }
  </code></pre>
  
  <p>This code is executed in onCreate and onRestart. Everything works OK if the activity is not launched yet. </p>
  
  <p>But if it was launched earlier the screen is not turned off.</p>
  
  <ul>
  <li>onRestart is called first</li>
  <li>onResume is then called</li>
  <li>onPause is called immediately</li>
  </ul>
  
  <p>So the activity is not launched. My question is how to turn on the screen in such situation. (I am using API 15).</p>