I create an alarm with notification, but when I open MainActivity through the notification, another MainActivity is open over the previous and if I close MainActivity there is another MainActivity under.
This is the code of my BroadcastReceiver:
@Override
public void onReceive(Context context, Intent intent)
{
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context);
mBuilder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("E' ora di colazione!")
.setContentText("Cosa c'è per colazione?")
.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}