本地通知崩溃应用程序android java

本地通知崩溃应用程序android java,java,android,localnotification,Java,Android,Localnotification,当我尝试从本地通知打开应用程序时,应用程序崩溃。 通知应在5秒后发送,但有时会发送,有时需要更长时间,有时根本不发送 public void sendPushNotificationUpdate() { new Print("SEND NOTIFICATION"); AlarmManager service = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(My

当我尝试从本地通知打开应用程序时,应用程序崩溃。 通知应在5秒后发送,但有时会发送,有时需要更长时间,有时根本不发送

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);
由于我发送了通知,因此日志显示:

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
////////////////////////////////////////////////

 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);
这就是我目前所拥有的。我在互联网上浏览了一下,但找不到任何解决我问题的方法。 谢谢你的帮助

与此不同,我要问一个关于本地通知的特定问题@

见这一行:

数据库的SQLiteConnection对象 /data/data/com.test/databases/db.db被泄露!请把你的头发修好 应用程序以正确结束正在进行的事务并关闭 当不再需要数据库时


这意味着您以前使用过数据库,但未关闭该对象。现在您正在泄漏数据库。正确处理数据库对象状态

发布日志猫错误您必须发布崩溃报告。很抱歉,stack没有正确保存代码。我现在已经包括了崩溃报告,看到database/data/data/com.test/databases/db.db的SQLiteConnection对象泄漏了!请修复应用程序以正确结束正在进行的事务,并在不再需要时关闭数据库。。这意味着您以前使用过数据库,但未关闭该对象。现在您正在泄漏数据库。正确处理数据库对象状态。