title: Android - Count Power button clicks and Start Activity
body: <p>I used the below code, but didnt find the solution.</p>
  
  <p><strong>MyReceiver.java:</strong></p>
  
  <pre><code>    import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import android.util.Log;
      import android.widget.Toast;
  
      public class MyReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
  
       Log.v("onReceive", "Power button is pressed.");
  
       Toast.makeText(context, "power button clicked", Toast.LENGTH_LONG)
               .show();
      }
  
  }
  </code></pre>
  
  <p>and <strong>MainActivity.java:</strong></p>
  
  <pre><code>    import android.os.Bundle;
      import android.app.Activity;
      import android.view.Menu;
  
      public class MainActivity extends Activity {
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
          }
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              getMenuInflater().inflate(R.menu.activity_main, menu);
              return true;
          }
      }
  </code></pre>
  
  <p>and <strong>AndroidManifest.xml:</strong></p>
  
  <pre><code>  &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;receiver android:name=".MyReceiver"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.SCREEN_OFF"&gt;&lt;/action&gt;
          &lt;action android:name="android.intent.action.SCREEN_ON"&gt;&lt;/action&gt;
          &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED"&gt;&lt;/action&gt;
          &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"&gt;&lt;/action&gt;
           &lt;action android:name="android.intent.action.ACTION_SHUTDOWN"&gt;&lt;/action&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>But i am not getting any Toast Messages on click of <code>Power Button</code>. Please help me on how to get Count of <code>PowerButton</code> clicks and if the clicks equals to 5 then move to another <code>actvity</code>. Please help me to acheive this?</p>