Я создаю уведомление на деятельности под названием Главного меню с помощью будильника здесь кодУведомления запускается снова и снова
Intent myIntent = new Intent(MainMenu.this, SyncService.class); AlarmManager alarmManager = (AlarmManager)context.getSystemService(ALARM_SERVICE); pendingIntent = PendingIntent.getService(MainMenu.this, 1, myIntent,0); Calendar calforAlram = Calendar.getInstance(); calforAlram.set(Calendar.HOUR_OF_DAY, 20); calforAlram.set(Calendar.MINUTE, 46); calforAlram.set(Calendar.SECOND, 0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calforAlram.getTimeInMillis(), 24 * 60 * 60 * 1000, pendingIntent); alarmManager.cancel(pendingIntent);
В полученном уведомлении, по щелчку уведомления я должен открыть ту же Mainmenu
деятельности ,
Проблема: снова еще одно уведомления генерируется, снова нажмите на уведомлении снова деятельность Главного меню будет открывать и продолжает
Вот код уведомления
NotificationManager mManager = (NotificationManager) getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),MAFLogonActivity.class);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("XXXXXXXX")
.setContentText("Please sync data.").setAutoCancel(true);
intent1.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(), 1, intent1, 0);
notification.setContentIntent(pendingNotificationIntent);
Log.d("On service", "Alarms set for everyday 2 pm.");
mManager.notify(0, notification.build());
return Service.START_NOT_STICKY;
Считаете ли вы использование 'IntentService'? Он завершит работу, когда работа будет выполнена, а затем не будет вызвана снова, пока она не будет вызвана снова. – Marat
Вы использовали мое решение? –
да это сработало спасибо – vish