title: Problems with android lock in custom lock screen app
body: <p>I built a custom lock screen app that uses a broadcast receiver and service to listen for when the user turns on or off the screen and from there launch my activity. The activity is supposed to completely replace the lock screen. In order to do this my app is supposed to disable the android stock lock so that my app can function as the new lock screen. </p>
  
  <p>Instead what happens is once the application is first installed the the service first started the application appears to be working. and when the user first turns off the screen of their phone when they turn it back on they are presented with my app running on top and is able to unlock their phone with my app. But then once inside the android OS if the user presses the home button the next time they turn off the screen and turn it back on instead of being brought back to my application they are brought to the stock unlock screen with my application open underneath it, when it should be on top.</p>
  
  <p>Here is my code:</p>
  
  <p>My Service:</p>
  
  <pre><code>public class MyService extends Service {
      @Override
      public IBinder onBind(Intent intent) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public void onCreate() {
  
          super.onCreate();
          Log.d("MyService","Service STARTED");
          final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
          filter.addAction(Intent.ACTION_SCREEN_OFF);
          final BroadcastReceiver mReceiver = new ScreenReceiver();
          registerReceiver(mReceiver, filter);
      }
  }
  </code></pre>
  
  <p>My broadcast receiver:</p>
  
  <pre><code>public class ScreenReceiver extends BroadcastReceiver {
  
  public static ArrayList&lt;String&gt; runningApplications = new ArrayList&lt;String&gt;();
  private Context ctext;
  public static boolean screenIsLocked;
  public static KeyguardManager keyguardManager;
  public static KeyguardLock lock;
  
  @Override
  public void onReceive(final Context context, final Intent intent) {
      ctext = context;
      keyguardManager = (KeyguardManager)ctext.getSystemService(Activity.KEYGUARD_SERVICE);
      lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE);
      lock.disableKeyguard();
  
  
      if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
          screenIsLocked = true;
          Log.d("ScreenReceiver", "False");
  
          Intent intenti = new Intent();
          intenti.setClass(context, starterActivity.class);
          intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(intenti);
  
  
      } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
          screenIsLocked = false;
          Log.d("ScreenReceiver", "True");
  
                      Intent intenti = new Intent();
                      intenti.setClass(context, starterActivity.class);
                      intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                      context.startActivity(intenti);
      }
  }
  </code></pre>
  
  <p>My activity that is started is basically empty with just one unlock button that calls <code>finish();</code> when pressed.</p>