My app crashes when I try to open it from local notification. Notification should be sent after 5 seconds, but sometimes it does so, sometimes it takes longer, sometimes it is not sent at all.
public void sendPushNotificationUpdate() {
    new Print("SEND NOTIFICATION");
    AlarmManager service = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(MyService.this, LocalNotification.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pending = PendingIntent.getBroadcast(MyService.this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    Calendar cal = Calendar.getInstance();
    // Start 1 month after boot completed
    cal.add(Calendar.SECOND, 5);
    new Print("send notification at " + cal.getTime());
    //
    // Fetch every 1 month
    // InexactRepeating allows Android to optimize the energy consumption
    // service.setInexactRepeating(AlarmManager.RTC_WAKEUP ,cal.getTimeInMillis(), AlarmManager.ELAPSED_REALTIME , pending);
    service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, pending);
}
////////////////////////////////////////////////////////////////////////////////
 Intent notificationIntent = new Intent(context, MainActivity.class);
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP |
                Intent.FLAG_ACTIVITY_NEW_TASK);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(notificationIntent);
        PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, 0);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Notification notification = builder
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("TEST")
                .setContentText(title)
                .setSound(soundUri)
                .setAutoCancel(false)
                .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(title))
                .setPriority(Notification.PRIORITY_MAX)
                .setContentIntent(pendingIntent).build();
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
Since I send the notification this is what the log shows:
I/System.out: RECEIVE LOCAL NOTIFICATION
   I/System.out: DISABLE SERVICEEEEEEEEEEEEEEEEEEEEEEEEEEEE
   I/System.out: Database exists
   D/Background mode ->: VERIFY INTERNET CONNECTION
   D/Background mode ->: NO CONNECTION AVAILABLE
   I/System.out: DELEGATE STARTS
   V/FA: onActivityCreated
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.test/databases/db.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   V/ztgl: asset != NULL
   I/System.out: Between 22.02.2017 - 10:50 and 22.02.2017 - 11:20 there are:
   I/System.out: 0 days, 0 hours, 30 minutes, 0 seconds
   V/FA: Using measurement service
   V/FA: Connecting to remote service
   V/FA: Activity resumed, time: 182309534
   I/Choreographer: Skipped 30 frames!  The application may be doing too much work on its main thread.
   D/Background mode ->: Service destroyed
   I/System.out: Between 22.02.2017 - 10:50 and 22.02.2017 - 11:20 there are:
   I/System.out: 0 days, 0 hours, 30 minutes, 0 seconds
   I/Process: Sending signal. PID: 20941 SIG: 9
////////////////////////////////////////////////
that's what I have at the moment. I've had a look around on the internet but couldn't find anything to solve my problem. thanks for your help.
Unlike Unfortunately MyApp has stopped. How can I solve this? , I'm asking a specific question regarding local notification. @Vlad Matvienko
 
     
    