【问题标题】:More than one status bar notification多个状态栏通知
【发布时间】:2011-03-25 16:53:39
【问题描述】:

我可以从一个程序(服务)在状态栏中创建多个通知,还是应该使用可点击的对象列表(例如LinearLayout)创建新的活动?

【问题讨论】:

    标签: android notifications statusbar


    【解决方案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 的通知。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多