title: lock screen sometime not display android
body: <p>i created lock screen application.. Sometimes it give me a problem. problem is that some time default lock screen display rather than my lock screen and some time directly home screen display. i donot know where is the problem. please give me suggestion about this.</p>
  
  <p>LockScreenActivity:
  Use</p>
  
  <pre><code>KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); 
  KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 
  lock.disableKeyguard(); 
  </code></pre>
  
  <p>and create ScreenReceiver:</p>
  
  <pre><code>ACTION_SCREEN_OFF
  ACTION_SCREEN_ON
  ACTION_BOOT_COMPLETED
  </code></pre>
  
  <p>Refer this link: <a href="http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/" rel="nofollow">http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/</a></p>
  
  <p>in manifeast file : declare service and receiver and permission</p>
  
  <p>The problem is in BroadcastReceiver when</p>
  
  <pre><code>if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
      //call activity
  }else if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
  }
  </code></pre>
  
  <p>but the activity call after screen on.. so what is missing or what is problem.. why it is happn pls rply. </p>
  
  <p>Hi here is my code :</p>
  
  <pre><code>public class myReceiver extends BroadcastReceiver {
      public static boolean wasScreenOn = true;
  
      @Override
      public void onReceive(final Context context, Intent recievedIntent) {
  
          if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
              wasScreenOn = false;
  
              Intent intent = new Intent(context,
                      myActivity.class);
              intent.setAction(Intent.ACTION_MAIN);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
              intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
              intent.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                      context.startActivity(intent
                      .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
  
          } else if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
              wasScreenOn = true;
          }
      }
  }
  </code></pre>
  
  <p>The activity is calling after when action screen on is call .</p>