title: onReceive never called
body: <p>I have the following code
  I want to detect the screen off of the phone
  But the function onReceive never is never called
  can anyone give me a solution.
  Please help.
  if anyone has anyother working code please help.
  Thank you</p>
  
  <pre><code>package com.pack;
  
  import android.app.Activity;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.os.Bundle;
  
  public class Screen extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          IntentFilter filter = new IntentFilter();
          filter.addAction(Intent.ACTION_SCREEN_OFF);
       Context con = this;
          this.registerReceiver(new BroadcastReceiver() {
  
                @Override
                public void onReceive(Context context, Intent intent) {
                 System.out.println("Screen off...................");
                }
              }, new IntentFilter(Intent.ACTION_SCREEN_OFF));
      }
  
  }
  </code></pre>