当我尝试从本地通知中打开它时,我的应用程序崩溃了。 通知应在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
/////////////////////////////////////////////// /
这就是我现在所拥有的。我在互联网上环顾四周,但无法找到解决问题的方法。 谢谢你的帮助。
与Unfortunately MyApp has stopped. How can I solve this?不同,我提出了有关本地通知的具体问题。 @ Vlad Matvienko
答案 0 :(得分:1)
见这一行:
数据库的SQLiteConnection对象 /data/data/com.test/databases/db.db泄露了!请修理你的 应用程序正确结束正在进行的事务并关闭 数据库不再需要时。
这意味着您之前使用过数据库,并且没有关闭该对象。现在你正在泄漏数据库。正确处理数据库对象状态。