title: how to Create and register the BroadcastReceiver in code
body: <p>i am new on android .
  I am trying register the BroadcastReceiver in code at my activity. this is my code:</p>
  
  <p>MyReciever class:</p>
  
  <pre><code>public class MyReciever extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
  
      Log.i("===&gt;", "onReceive: "+  intent.getAction());
      Toast.makeText(context, "I got it "+ intent.getIntExtra("MyValue",0), Toast.LENGTH_SHORT).show();
  
  }
  }
  </code></pre>
  
  <p>myActivity:</p>
  
  <pre><code>    @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myReciever = new MyReciever();
      intentFilter = new IntentFilter();
      intentFilter.addAction("test");
  }
  
  @Override
  protected void onResume() {
      registerReceiver(myReciever, intentFilter);
      super.onResume();
  }
  }
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.safarayaneh.mybroadcastreciever"&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>when i run my app, nothing happen and toast not comes up! I've read <a href="https://stackoverflow.com/questions/14397336/how-to-register-a-receiver-in-the-main-activity">this</a> and <a href="http://code4reference.com/2012/09/register-unregiste-broadcast-receiver-part/" rel="nofollow noreferrer">this</a> article and i don't understand that where is my problem. </p>