Skip to content

This Android library is used to fix some serious bugs of Toast with the easiest way.

License

Notifications You must be signed in to change notification settings

ryuunoakaihitomi/ReToast

Repository files navigation

ReToast

Build CI Maven metadata URL

Introduction

This Android library is used to fix some serious bugs of android.widget.Toast with the easiest way.

Details

What bugs does it fix?

  • before 10 (<29): Notification Permission

Always allow toasts from foreground apps (The commit to fix).

  • from 8.1 to 9.0 (27-28): Rate Limit

Each package can enqueue one toast at a time.

Allow apps to queue multiple toast messages.

  • 7.1 (25): BadTokenException

Toast with UI stress causes crash.

Why not use other libraries?

Most library that fix these bugs are invasive, so we have to replace all existing Toasts, it can be pretty messy in some large projects.

Unlike them, this library is globally effective and uses ContentProvider.onCreate() to automatically initialize in order to make less invasive (Initializing is almost instant). We can continue doing all our other work just like before.

Usage

Import the library in app(module-level) build.gradle:

dependencies {
    repositories {
        maven {
            url 'https://raw.githubusercontent.com/ryuunoakaihitomi/maven-repository/master' // 👈
        }
    }
    runtimeOnly 'github.ryuunoakaihitomi.retoast:retoast:2.0.0' // 👈
    // ...
}

For Android studio Arctic Fox 2020.3.1+

If you encountered this error,

Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'app\build.gradle'

you have to perform it in two steps...

① Import the maven repository in settings.gradle:

dependencyResolutionManagement {
    repositories {
        // ...
        // 👇
        maven {
            url 'https://raw.githubusercontent.com/ryuunoakaihitomi/maven-repository/master'
        }
    }
}

② Import the library in app(module-level) build.gradle

dependencies {
    // ...
    runtimeOnly 'github.ryuunoakaihitomi.retoast:retoast:2.0.0'
}

THAT'S ALL! We can use Toast or other fancy Toast-based UI libraries as before, but there's no need to worry about the bugs anymore.

Compatibility

If the app's minSdkVersion >= API Level 29, it's almost impossible to encounter these bugs, which have been fixed on platforms where the app is compatible (Tested on Android 10 and 11 release). We'd better remove ReToast from the app. In this case, the library will throw a UnsupportedOperationException in order to remind us to remove it.

Since Android 10, the vulnerability used by this library does have also been fixed , so even if these features1 bugs reappear, we just cannot let it work on the newer platforms any more. 😟

ReToast also ships with some embedded lint rules to guide us use it in the right way as much as possible. However, there is no guarantee that these rules will function properly all the time. Documentations are always the most reliable.

Acknowledgments

References

Inspired by these two articles (are all in Chinese), this library is made. These were supposed to be unrelated stuff, but I suddenly found the connection between them.

解决通知关闭Toast失效问题

Android 7.X Toast Bug

Assistance

DeweyReed helped find a bug.


1 Android 12 did bring back rate limit for all apps, the compatibility change is RATE_LIMIT_TOASTS.

About

This Android library is used to fix some serious bugs of Toast with the easiest way.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages