title: Will the BroadcastReceiver keep running after I have installed .apk file with BroadcastReceiver?
body: <p>I think the <code>BroadcastReceiver AlarmManagerBroadcastReceiver</code> will keep running even if I exit the app. I think the <code>BroadcastReceiver</code> will restore and keep running automatically when I reboot system. In order to stop the Broadcast receiver, I have to uninstall the app, right?</p>
  
  <p><strong>Layout</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android='http://schemas.android.com/apk/res/android'
      xmlns:tools='http://schemas.android.com/tools'
      android:layout_width='match_parent'
      android:layout_height='match_parent' 
      android:orientation='vertical'&gt;
  
      &lt;Button
          android:layout_width='fill_parent'
          android:layout_height='wrap_content'
          android:padding='@dimen/padding_medium'
          android:text='@string/start_repeating_alarm'
          android:onClick='startRepeatingAlarm'
          tools:context='.EnableDisableBroadcastReceiver' /&gt;
  
      &lt;Button
         android:layout_width='fill_parent'
         android:layout_height='wrap_content'
         android:padding='@dimen/padding_medium'
         android:text='@string/cancel_alarm'
         android:onClick='cancelAlarm'
         tools:context='.EnableDisableBroadcastReceiver' /&gt;
  
      &lt;Button
          android:layout_width='fill_parent'
          android:layout_height='wrap_content'
          android:padding='@dimen/padding_medium'
          android:text='@string/enable_broadcast_receiver'
          android:onClick='enableBroadcastReceiver'
          tools:context='.EnableDisableBroadcastReceiver' /&gt;
  
     &lt;Button
         android:layout_width='fill_parent'
         android:layout_height='wrap_content'
         android:padding='@dimen/padding_medium'
         android:text='@string/disable_broadcast_receiver'
         android:onClick='disableBroadcastReceiver'
         tools:context='.EnableDisableBroadcastReceiver' /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Resources</strong></p>
  
  <pre><code>&lt;resources&gt;
      &lt;string name='app_name'&gt;EnableDisableBroadcastReceiver&lt;/string&gt;
      &lt;string name='enable_broadcast_receiver'&gt;Enable Broadcast Receiver&lt;/string&gt;
      &lt;string name='disable_broadcast_receiver'&gt;Disable Broadcast Receiver&lt;/string&gt;
      &lt;string name='start_repeating_alarm'&gt;Start Repeating Alarm&lt;/string&gt;
      &lt;string name='cancel_alarm'&gt;Cancel Alarm&lt;/string&gt;
      &lt;string name='menu_settings'&gt;Settings&lt;/string&gt;
      &lt;string name='title_activity_enable_disable_boradcast_receiver'&gt;EnableDisableBoradcastReceiver&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>Broadcast Receiver</strong> </p>
  
  <pre><code>public class AlarmManagerBroadcastReceiver extends BroadcastReceiver {
  
      final public static String ONE_TIME = 'onetime';
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
           //You can do the processing here update the widget/remote views.
           StringBuilder msgStr = new StringBuilder();
           //Format time.
           Format formatter = new SimpleDateFormat('hh:mm:ss a');
           msgStr.append(formatter.format(new Date()));
  
           Toast.makeText(context, msgStr, Toast.LENGTH_SHORT).show();
  
      }
  }
  </code></pre>
  
  <p><strong>Activity</strong></p>
  
  <pre><code>public class EnableDisableBroadcastReceiver extends Activity {
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      public void startRepeatingAlarm(View view)
      {
          AlarmManager am=(AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
          Intent intent = new Intent(this, AlarmManagerBroadcastReceiver.class);
          PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0);
          //After after 2 seconds
          am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 4 , pi); 
          Toast.makeText(this, 'Started Repeating Alarm', Toast.LENGTH_SHORT).show();
      }
  
      public void cancelAlarm(View view)
      {
          Intent intent = new Intent(this, AlarmManagerBroadcastReceiver.class);
          PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);
          AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
          alarmManager.cancel(sender);
          Toast.makeText(this, 'Cancelled alarm', Toast.LENGTH_SHORT).show();
      }
  
      public void enableBroadcastReceiver(View view){
          ComponentName receiver = new ComponentName(this, AlarmManagerBroadcastReceiver.class);
          PackageManager pm = this.getPackageManager();
  
          pm.setComponentEnabledSetting(receiver,
                  PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                  PackageManager.DONT_KILL_APP);
          Toast.makeText(this, 'Enabled broadcast receiver', Toast.LENGTH_SHORT).show();
      }
  
      public void disableBroadcastReceiver(View view){
          ComponentName receiver = new ComponentName(this, AlarmManagerBroadcastReceiver.class);
          PackageManager pm = this.getPackageManager();
  
          pm.setComponentEnabledSetting(receiver,
                  PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                  PackageManager.DONT_KILL_APP);
          Toast.makeText(this, 'Disabled broadcst receiver', Toast.LENGTH_SHORT).show();
      }   
  }
  </code></pre>