title: Android Galaxy S4 -- Activity that is visible over lock screen
body: <p>A few years ago, I wrote an alarm app that worked on Android 2, and I'm now trying to upgrade it to work on Android 4.  Specifically, on the Samsung Galaxy S4.</p>
  
  <p>On Android 2, if the phone was sleeping, it would wake the phone up and display a "Snooze or Dismiss" screen over the lock screen.</p>
  
  <p>On Android 4, it wakes the phone up, but you have to unlock it, then open the notifications area, then click the alarm's notification, before you can hit "Dismiss."</p>
  
  <p>I have always been using this code to do the waking:</p>
  
  <pre><code>getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
              | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
              | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
              | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  </code></pre>
  
  <p>I have read 8 different stackoverflow questions on this matter.  Most of them give the code above, which worked for me years ago in Android 2 but doesn't work in Android 4.  But none of them have helped me solve this problem.  Here are the questions that I read and tried:</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/q/18890143">Android: remove or disable programmatically the Lock Screen on Samsung Galaxy S2 device</a></p>
    
    <p><a href="https://stackoverflow.com/q/6371432">How to display a fullscreen TYPE_SYSTEM_ALERT window?</a></p>
    
    <p><a href="https://stackoverflow.com/q/5009602">How do I create an Activity that is visible on top of the lock screen</a></p>
    
    <p><a href="https://stackoverflow.com/q/17866419">How to start a dialog (like alarm dimiss /snooze) that can be clicked without unlocking the screen</a></p>
    
    <p><a href="https://stackoverflow.com/q/3629179">Android activity over default lock screen</a></p>
    
    <p><a href="https://stackoverflow.com/q/16299448">android device locked, yet want alarm to sound and dialog to appear</a></p>
    
    <p><a href="https://stackoverflow.com/q/18504795">Android dialog over lock screen</a></p>
    
    <p><a href="https://stackoverflow.com/q/17260986">Show dialog with touch events over lockscreen in Android 2.3</a></p>
  </blockquote>
  
  <p>Does anyone have any ideas about what's changed in Android 4 that may have caused this?</p>
  
  <p><strong>EDIT:</strong> Here is one of the simplest examples I've seen of an alarm dialog that doesn't come up "minimized." It does not, as written, appear over the lockscreen, but you can fix that with <code>WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED</code></p>
  
  <p><a href="http://wptrafficanalyzer.in/blog/setting-up-alarm-using-alarmmanager-and-waking-up-screen-and-unlocking-keypad-on-alarm-goes-off-in-android/" rel="nofollow noreferrer">http://wptrafficanalyzer.in/blog/setting-up-alarm-using-alarmmanager-and-waking-up-screen-and-unlocking-keypad-on-alarm-goes-off-in-android/</a></p>
  
  <p>It's written with a FragmentActivity and a DialogFragment, but it still works as an Activity. It uses an AlertDialog.Builder to make the dialog, and if you try to do it with an XML layout, it won't work.  Why?</p>