У меня есть рабочие уведомления (со службой) в моем приложении, и он работает нормально, когда приложение находится в onPause, но когда я закрываю приложение, текст/название уведомления имеет значение null и появляется уведомление , но без названия/тела.Уведомления на Android оповещаются, когда приложение закрыто
Вот код уведомления строитель:
public int onStartCommand(Intent intent, int flag, int startId)
{
super.onStartCommand(intent , flag, startId);
String titleS = Utils.Title;
String bodyS = Utils.Body;
Context context = this.getApplicationContext();
notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
Intent mIntent = new Intent(this, MainActivity.class);
pendingIntent = PendingIntent.getActivity(context, 0, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(titleS);
builder.setContentText(bodyS);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
return START_NOT_STICKY;
}
Очевидно, что Титулы и Bodys равно нулю, когда приложение закрыто, и поэтому уведомление появляются без какой-либо информации.
Мой вопрос заключается в том, как правильно сохранить или отобразить эти данные в уведомлении, когда мое приложение закрыто?