我有一个服务,它创建一个通知,然后定期更新某些信息。大约12分钟后,手机崩溃并重新启动,我相信这是由于内存泄漏导致的以下代码与我如何更新通知,请有人检查/建议我,如果是这种情况,我做错了什么。
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
创建通知:
private void createNotification() {
Intent contentIntent = new Intent(this,MainScreen.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent appIntent =PendingIntent.getActivity(this,0, contentIntent, 0);
contentView = new RemoteViews(getPackageName(), R.layout.notification);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, "");
notification = new Notification();
notification.when=System.currentTimeMillis();
notification.contentView = contentView;
notification.contentIntent = appIntent;
}
private void updateNotification(String text){
contentView.setTextViewText(R.id.text, text);
mNotificationManager.notify(0, notification);
}
提前谢谢。