前奏曲
通知にクロノメーターを追加しようとしています。クロノメーターはサービスです。毎秒、この行が呼び出されます (継続 Thread は「実行中の」ブール値であり、timeString は時間を示す精巧な文字列です):
NotificationChrono.updateNotification(getApplicationContext(), continueThread,
NOTIF_ID, timeString, "Chronometer", notificationManager);
これは NotificationChrono クラスです。
public class NotificationChrono {
static public void updateNotification(Context context, boolean running,
int id, String title, String text,
NotificationManager notificationManager) {
Intent stopIntent = new Intent("com.corsalini.david.barcalc.STOP");
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context,
0, stopIntent, 0);
Intent startIntent = new Intent(
"com.corsalini.david.barcalc.STARTPAUSE");
PendingIntent startPendingIntent = PendingIntent.getBroadcast(context,
0, startIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context)
.setContentText(context.getString(R.string.notif_text))
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_action_alarm_2)
.setAutoCancel(false)
.setOngoing(running)
.setOnlyAlertOnce(true)
.setContentIntent(
PendingIntent.getActivity(context, 10, new Intent(
context, FrontActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), 0))
.addAction(
running ? R.drawable.ic_action_pause
: R.drawable.ic_action_play,
running ? context.getString(R.string.pause) : context
.getString(R.string.start), startPendingIntent)
.addAction(R.drawable.ic_action_stop,
context.getString(R.string.stop), stopPendingIntent);
notificationManager.notify(id, builder.build());
}
}
問題
1 秒ごとに通知が削除され、再作成されます。視覚的には、1 秒ごとに通知が消えて通知リストに再表示されることを意味します。
私が望むのは、毎秒完全に通知を再作成するのではなく、TITLE テキストを更新することです。出来ますか?