0

I am building a note app, that uses alarm manager to set multiple notifications, but when a reboot the phone, the notification is not showing up.

I tried to save notifications in a db, but is not working.

Can anyone help me?

Jhonatan Sabadi
  • 838
  • 7
  • 14
  • Alarms do not persist through a reboot. You need to set them again at boot up. Is that your problem? It's not quite clear what you're saying. – Mike M. Feb 08 '17 at 00:46

2 Answers2

1

Here is how you start your app after reboot automatically. After restart, check your db and re-post the notifications, what you need.

Community
  • 1
  • 1
matheszabi
  • 594
  • 5
  • 16
1

You need to add a receiver that launches a Service after a reboot.

In your manifest register for Boot Complete

... ...

In your boot receiver, launch a service.

public class MyRebootReceiver extends BroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {
      Intent serviceIntent = new Intent(context, MeCorpServiceClass.class);
      serviceIntent.putExtra("caller", "RebootReceiver");
      context.startService(serviceIntent);
   }

}

Here is an example for a service class to run in the background.

   public class MeCorpServiceClass extends IntentService{

     @Override
     protected void onHandleIntent(Intent intent){
         String intentType = intent.getExtras().getString("caller");
         if(intentType == null) return;
         if(intentType.Equals("RebootReceiver"))
              //Do reboot stuff
         //handle other types of callers, like a notification.
     }
 }

OR Just use a third party like Urban AirShip, which handles all that for you.

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38