我有一个服务,它会创建一个通知,然后定期用某些信息更新它.电话崩溃并重新启动大约12分钟后,我认为这是由于以下代码中的内存泄漏导致我如何更新通知,有人请检查/建议我是否是这种情况和我我做错了.
的onCreate:
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Run Code Online (Sandbox Code Playgroud)
createNotification:
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;
}
Run Code Online (Sandbox Code Playgroud)
updateNotification:
private void updateNotification(String text){
contentView.setTextViewText(R.id.text, text);
mNotificationManager.notify(0, notification);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.