0

У меня есть передний план службы в моем приложении, которое имеет динамически обновляемый текст уведомления, и я могу обновить это просто отлично от жгутов службы сUpdate notificaton от активности

startForeground(Constants.FOREGROUND_ID, buildForegroundNotification()); 
} 

private Notification buildForegroundNotification() { 
    NotificationCompat.Builder b = new NotificationCompat.Builder(this); 
    b.setOngoing(true); 
    b.setContentIntent(getPendingIntent(this)); 
    b.setContentTitle(getString(R.string.app_name)); 
    b.setContentText(getString(R.string.time) + " " + number); 
    b.setSmallIcon(R.drawable.ic_launcher); 
    return b.build(); 
} 

Но я хочу также иметь возможность обновлять его из Activity, как я могу это сделать без перезапуска службы?

ответ

1

Вы можете использовать этот подход

final Notification notification = buildForegroundNotification(); 
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(Constants.FOREGROUND_ID, notification); 
Смежные вопросы