我可以在一个程序(服务)的状态栏中创建多个通知,还是应该创建一个带有可点击列表(例如LinearLayout
)对象的新活动?
答案 0 :(得分:1)
您当然可以从服务或应用程序创建多个通知,但您必须问自己,作为用户,您希望应用程序向您发送垃圾邮件通知。我一直在我的远程服务中使用一个通知,只是通过更新其内容重用相同的通知。这是一个例子:
public void onPlaybackStarted(int currentTrack, Show show) {
notificationManager.cancel(R.layout.notification_playing);
notification.tickerText = show.getTracks().get(currentTrack).getName();
if (notificationView == null) {
notificationView = new RemoteViews(getPackageName(), R.layout.notification_playing);
}
notificationView.setTextViewText(R.id.notification_playing_track, show.getTracks().get(currentTrack).getName());
notificationView.setTextViewText(R.id.notification_playing_band, show.getArtist());
notificationView.setTextViewText(R.id.notification_playing_date, show.getDate());
Intent intent = new Intent(TrackPlayerService.this, ListTracksActivity.class)
.putExtra("track", currentTrack)
.putExtra("artist", show.getArtist())
.putExtra("date", show.getDate())
.putExtra("location", show.getLocation())
.putExtra("venue", show.getVenue())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notification.contentView = notificationView;
notification.contentIntent = PendingIntent.getActivity(TrackPlayerService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(R.layout.notification_playing, notification);
}
如果您的通知不是循环播放,这意味着您需要同时通知用户3到4个不同的内容,那么获得打开ListActivity的通知将是最佳方式。