"Плохое уведомление отправлено - не удалось развернуть RemoteViews для: StatusBarNotification" возникает, когда мое приложение удаляется из последних приложений

Я пытаюсь сделать демо, которое может периодически показывать пользовательское уведомление.

Для этого я использовал Remoteviews, чтобы обновить вид уведомления. Поместите это уведомление в метод onReceive BroadcastReceiver. Затем периодически вызывайте его с помощью AlarmManager.

Все работает просто отлично, если мое демо-приложение не удалено из последних приложений. Это принудительно завершилось, и когда я проверил в журнале Android, я увидел эту ошибку: "Плохое уведомление отправлено - Не удалось развернуть RemoteViews для: StatusBarNotification"

Не могли бы вы помочь мне решить эту проблему?

Ниже мой код:

Intent alarmIntent = new Intent(this, PeriodicTaskReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);

manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
int interval = 10000;
manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);

PeriodicTaskReceiver - это мой настроенный класс BroadcastReceiver:

public void onReceive(Context context, Intent intent) {
        repository = new LocalRepository();
        Notification(context, repository.getData());
        }
    }

Способ уведомления:

public void Notification(Context context, Data data) {
        // Set Notification Title
        String strtitle = context.getString(R.string.notificationtitle);
        // Open NotificationView Class on Notification Click
        Intent intent = new Intent(context, NotificationView.class);
        // Send data to NotificationView Class
        intent.putExtra("title", strtitle);
        // Open NotificationView.java Activity
        PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        RemoteViews customNotification = buildNotificationItem(data);

        // Create Notification using NotificationCompat.Builder
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context)
                // Set Icon
                .setSmallIcon(R.drawable.icon)
                        // Set PendingIntent into Notification
                .setContentIntent(pIntent)
                .setContent(customNotification);

        // Create Notification Manager
        NotificationManager notificationmanager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = builder.build();
//        notification.bigContentView = customNotification;
        // Build Notification with Notification Manager
        notificationmanager.notify(0, notification);
    }

И метод обрабатывает контент для моих Remoteviews:

private RemoteViews buildNotificationItem(Data data){
        RemoteViews view = new RemoteViews(Global.PACKAGE_NAME, R.layout.notification_item);
        view.setTextViewText(R.id.notification_tags, data.getTitle());
        view.setTextViewText(R.id.notification_content, data.getContent());
        return view;
    }

Спасибо

0 ответов

Другие вопросы по тегам