How To Remove my own app notification when I'm on the app
<p>I create an app with button for 5 sec notification i'm getting the notification when I'm on the app or outside 
so I want to get the notification just when I'm not working on the app
and when I click on the notification enters the app and the notification stops but when I reclose the  app the notification appears every 5 min/sec.</p>

<p>mainactivity.java</p>

<pre><code> Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
        button = (Button)findViewById(R.id.btn1);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Calendar calendar =Calendar.getInstance();



            Intent intent = new Intent (getApplicationContext(),AlertReceiver.class);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),100,intent,PendingIntent.FLAG_UPDATE_CURRENT);

            AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),AlarmManager.INTERVAL_FIFTEEN_MINUTES/180,pendingIntent);


        }
    });

}
</code></pre>

<p>AlertReciver.class</p>

<pre><code>public class AlertReceiver extends BroadcastReceiver {



@Override
public void onReceive(Context context, Intent intent) {
     NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent repeating_intent = new Intent(context,Activity12.class);
    repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context,100,repeating_intent,PendingIntent.FLAG_UPDATE_CURRENT);
  NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentIntent(pendingIntent)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("AAA")
            .setContentText("BBB")
          .setAutoCancel(true);

        notificationManager.notify(100,builder.build());
</code></pre>

<p>Activity12.class is empty just textview there...!</p>