java - 可显示的 Toast 数量有限制吗?

标签 java android user-interface limit toast

在 MainActivity 中,我需要显示 getApplicationContext().fileList() 返回的所有文件,但只会显示大约前 50 个 Toast。

有一些限制吗?

String[] fileList = getApplicationContext().fileList();

Toast.makeText(getApplicationContext(), fileList.length + " files", Toast.LENGTH_LONG).show();

for (String fileName : fileList)
{
    Toast.makeText(getApplicationContext(), fileName, Toast.LENGTH_LONG).show();
}

谢谢

最佳答案

2023 年 2 月更新

一个新的limit Android 12 中添加了 5 个排队 toast,preventing to queue too many toasts .

// To limit bad UX of seeing a toast many seconds after if was triggered.
static final int MAX_PACKAGE_TOASTS = 5;
if (count >= MAX_PACKAGE_TOASTS) {
    Slog.e(TAG, "Package has already queued " + count
            + " toasts. Not showing more. Package=" + pkg);
    return;
}

还有previous limit of 50 toasts在 Android 10 中更改为 25。

static final int MAX_PACKAGE_NOTIFICATIONS = 25;

原始答案

是的,Toasts 会排队,并且限制为 50 个 Toasts,您可以在 NotificationManagerService 中查看检查情况。类

if (count >= MAX_PACKAGE_NOTIFICATIONS) {
    Slog.e(TAG, "Package has already posted " +
           + " toasts. Not showing more. Package=" + pkg);
    return;
}

并且 MAX_PACKAGE_NOTIFICATIONS 声明为

static final int MAX_PACKAGE_NOTIFICATIONS = 50;

关于java - 可显示的 Toast 数量有限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56514996/

相关文章:

java - Java中的正则表达式?

java - 在线文档编辑器 - 我从哪里开始、从什么开始?

android - 运行时判断target是模拟器还是手机

java - (Java) GUI NumberFormatException 捕获异常,但挂起窗口

c++ - Qt 子窗口放置

java - 在 Java 中从 String(也包含字母)获取负 int

java - 当我读取 GPS 位置时 Android 返回 null

android - 未在虚拟或真实设备上安装代码和应用程​​序下带有红线的Gradle代码

android - Freetype Library 提供三重纹理和奇怪的符号

css - 如何在html组合框中具有树状结构