1

I want to notification worked after a reboot. I reminder starts but once. If I then change the date on the phone ahead - then no notifications. Only if you run the application again, then they will. That is, after you restart the phone without launching the application notifications appear only once - when you start your phone.

I set a time of notification in my MainActivity:

    Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, c1.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

MyAlarmService(onCreate):

mManager =(NotificationManager)this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
       Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);

   Notification notification = new Notification(R.drawable.ic_launcher,"Title", System.currentTimeMillis());

   intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);

   PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
   notification.flags |= Notification.FLAG_AUTO_CANCEL;
   notification.setLatestEventInfo(this.getApplicationContext(), "Title", "Description", pendingNotificationIntent);

   mManager.notify(0, notification);

MyReceiver:

Intent service1 = new Intent(context, MyAlarmService.class);
context.startService(service1);

AndroidManifest(MyReceiver and Service):

<service android:name=".MyAlarmService"
                 android:enabled="true"/>
        <receiver android:name=".MyReceiver"
            android:enabled="true"
            android:exported="false"
            android:label="MyReceiver">
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </receiver>
user3499878
  • 1,023
  • 2
  • 10
  • 15

1 Answers1

1

Notification (AlarmManager) are lost after reboot. It seems you need to reset Alarmanager setRepeating() on reboot

Please check this thread:

Repeating Alarm Manager After reboot

Community
  • 1
  • 1
fpanizza
  • 1,589
  • 1
  • 8
  • 15