停止排序Android通知

停止排序Android通知,android,notifications,Android,Notifications,我需要更新通知内容。我该怎么做 我在线程中这样做: notificationManager.notify(new Integer(id), notification); 我的通知机构: Intent notificationIntent = new Intent(this, SingleNewsActivity.class); notificationIntent.putExtra("id", id); notificationIntent.putExtra("titl

我需要更新通知内容。我该怎么做

我在线程中这样做:

notificationManager.notify(new Integer(id), notification);
我的通知机构:

    Intent notificationIntent = new Intent(this, SingleNewsActivity.class);
    notificationIntent.putExtra("id", id);
    notificationIntent.putExtra("title", title);
    notificationIntent.putExtra("text", text);

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(this, activity, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    activity++;

    builder.setContentIntent(contentIntent);
    builder.setSmallIcon(R.drawable.ic_bitcoin_notification);
    builder.setLargeIcon(bitmap);
    builder.setTicker(bar);
    builder.setContentTitle(title);
    builder.setContentText(text);
    builder.setWhen(System.currentTimeMillis());
    if(!silent){
        builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }
    builder.setVibrate(null);


    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(new Integer(id), notification);
并为3个通知设置唯一的静态ID,但在
线程
中,当我使用
通知
时,Android中的通知会改变位置


如何禁用排序并对通知执行静态定位?

Android先按优先级再按时间排序通知。如果你想让你的通知相对彼此保持有序,要么给它们不同的优先级,要么确保时间保持这种顺序。但这两个选项都不是很好的选择

通常不鼓励一个应用程序同时具有多个通知。也许您应该寻找一种方法来将它们合并为一个。如果您在通知的生成器中使用“setWhen”,它就会起作用

NotificationCompat.Builder builder = new NotificationCompat.Builder( context, "channel_name_here" );
builder.setContentTitle( "My notification" );
builder.setWhen( long uniqueTimeForEveryRequest );
NotificationManagerCompat.from( context ).notify( yourUniqueId, builder.build() );

你可以在android文档中看到更多关于“setWhen”的信息,我会给你一个场景,我有一个下载程序,我下载了3个项目,我想在通知中看到每个项目的百分比,每次每个项目改变百分比,它就会自动提升。另一个例子是多个定时器。在这种情况下,如何开发多个通知?我看到Utorrent应用程序,Opera浏览器下载就可以做到这一点。每当我有多个下载,它会在通知中显示2个项目,它们在更新时会保持不变。