1

I need to show a notification at 3 AM everyday. It is working fine and sending notification around 3 AM. But when I test in my phone the notification comes immediately. I read that if the time is already crossed it will show the notification. I am fine with this. Issue: When i click the notification it opens my activity correctly. But after few seconds it is loading another notification. If i click that again it is closing the notification and creating a new one after few seconds.

Here is the code: 1. In the activity onCreate()

Calendar calendar = Calendar.getInstance();
// calendar.set(Calendar.MONTH, 10);
// calendar.set(Calendar.YEAR, 2014);
// calendar.set(Calendar.DAY_OF_MONTH, 13);
calendar.set(Calendar.HOUR_OF_DAY, 3);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM, Calendar.AM);

Intent myIntent = new Intent(LitCalActivity.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(LitCalActivity.this, 0, myIntent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

In My service Class

public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);

        // Code to notification setup
        Intent litrcalintent = new Intent(this, LitCalActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("FromNotify", "YES");
        litrcalintent.putExtras(bundle);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0,
                litrcalintent, PendingIntent.FLAG_UPDATE_CURRENT);

        SimpleDateFormat format = new SimpleDateFormat("MMMM dd yyyy");
        String today = format.format(currentDate);
        String todayDetails = getLitCalDetails();

        Notification notification = new Notification.Builder(this)
                .setContentTitle("Liturgical Calendar for " + today)
                .setContentText(todayDetails)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentIntent(pIntent)
                .setAutoCancel(true)
                .setOngoing(false)
                .addAction(R.drawable.ic_launcher, "more...", pIntent).build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        notificationManager.notify(0, notification);


    }
Joseph Selvaraj
  • 2,225
  • 1
  • 21
  • 21
  • If you open the notification, within the time it will display new one. So first time when you get the notification, just stop getting notifications within that minute. Make sure to get only once at 3.00 AM. – Saritha G Jul 02 '15 at 05:22
  • http://stackoverflow.com/q/29509102/4447803, http://stackoverflow.com/a/30979787/4447803 try this link it may help you – Android Dev Jul 02 '15 at 05:47
  • This problem is still happening. The notificaiton is coming at least 4 times a day. Any help is much appreciated. – Joseph Selvaraj Jul 09 '15 at 06:39
  • @ Saritha G: how do we stop the notification within that minute? – Joseph Selvaraj Jul 11 '15 at 16:38

0 Answers0