Oreo上的Toast重叠问题(8.1)

Kac*_*hał 11 android android-8.1-oreo

我有祝酒问题.对于API 26及以下的吐司正确显示(下一个toast正在等待之前消失)但在Android 8.1(API 27)上它们相互覆盖.我的通知频道设置如下:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, 
                        NOTIFICATION_CHANNEL_NAME, 
                        NotificationManager.IMPORTANCE_DEFAULT);
    notificationManager.createNotificationChannel(notificationChannel);
    builder.setChannelId(NOTIFICATION_CHANNEL_ID);
}
Run Code Online (Sandbox Code Playgroud)

这为我修复了8.0的祝酒词,但在8.1上它们仍然重叠 喜欢这张照片

有没有办法解决这个问题而不是记住上次使用过的吐司并手动取消它?

编辑:

此线程的解决方法不起作用

/**
 * <strong>public void showAToast (String st)</strong></br>
 * this little method displays a toast on the screen.</br>
 * it checks if a toast is currently visible</br>
 * if so </br>
 * ... it "sets" the new text</br>
 * else</br>
 * ... it "makes" the new text</br>
 * and "shows" either or  
 * @param st the string to be toasted
 */

public void showAToast (String st){ //"Toast toast" is declared in the class
    try{ toast.getView().isShown();     // true if visible
        toast.setText(st);
    } catch (Exception e) {         // invisible if exception
        toast = Toast.makeText(theContext, st, toastDuration);
        }
    toast.show();  //finally display it
}
Run Code Online (Sandbox Code Playgroud)

吐司仍然过度

编辑2:我在Android Issue Tracker:链接上创建了这个错误的故事

Bah*_*man 1

private static final int TIME_DELAY = 4000;
private static long lastToastShowTime = 0;

showToast(final String msg, final Context ctx){
    final long pastTime = System.currentTimeMillis() - lastToastShowTime;
    if(pastTime > TIME_DELAY ){

        Toast.makeText(ctx, msg, Toast.LENGTH_LONG).show();
        lastToastShowTime = System.currentTimeMillis();

     }else{
        final long delay = TIME_DELAY - pastTime;
        lastToastShowTime = System.currentTimeMillis() + delay;
        postDelayed(new Runnable(

            @Override
            public void run() {
               try{
                  Toast.makeText(ctx, msg, Toast.LENGTH_LONG).show();
               catch(Exception e){
                  Log.e("TOAST_NOT_SHOWED", "Toast not showed: " + msg, e);
               }

            }

        ), delay);

    }
}
Run Code Online (Sandbox Code Playgroud)