purewriter / toastcompat Goto Github PK
View Code? Open in Web Editor NEWAn Android library to fix Toast BadTokenException
License: Apache License 2.0
An Android library to fix Toast BadTokenException
License: Apache License 2.0
ToastCompat.makeText(context, context.getText(textId), ToastCompat.LENGTH_LONG).show()无效,不显示提示;
原生Toast.makeText(context, context.getText(textId), ToastCompat.LENGTH_LONG).show()正常显示;
try { Log.d(TAG, "WindowManager's addView(view, params) has been hooked."); base.addView(view, params); } catch (BadTokenException e) { Log.i(TAG, e.getMessage()); if (badTokenListener != null) { badTokenListener.onBadTokenCaught(toast); } }
I found this in SafeToastContext.java , but is that Log.e better than Log.i ?
Not a big deal, but make me feel better.
Or you have other purposes about this? PLZ let me know, Thanks
Why do you need the method ToastCompat.getBaseToast()
? It seems it has never been used.
Hi,
i use your library for my project, i think it is a good way to solve the problem.
but i test in the phone (NUBIA Z17S android7.1.1), it could not show the toast.
there is no any useful message for debug.
i think some system use the (xxx instanceof WindowManagerImpl) to avoid
any hack from outside of system.
Those solution has some bug in some device: It do not show the toast in some device.
if somebody have to use these solution,it should make sure these code just use in android7.1.1
sorry for my poor english.
Hi,I noticed (on Samsung galaxy S7), when you show toast and keyboard is open, and then close keyboard, toast stays in the middle of the screen. Standard toast moves down when keyboard is hidden. Could you please check that ?
Thanks
你好在引入ToastCompat后今早在同事的手机上发现Toast不显示,手机型号如下
Redmi Note 3
MIUI 9.2
android 5.0.2
for WindowManager add view may throw ISE
/**
* Return the view.
*
* <p>Toasts constructed with {@link #Toast(Context)} that haven't called {@link #setView(View)}
* with a non-{@code null} view will return {@code null} here.
*
* <p>Starting from Android {@link Build.VERSION_CODES#R}, in apps targeting API level {@link
* Build.VERSION_CODES#R} or higher, toasts constructed with {@link #makeText(Context,
* CharSequence, int)} or its variants will also return {@code null} here unless they had called
* {@link #setView(View)} with a non-{@code null} view. If you want to be notified when the
* toast is shown or hidden, use {@link #addCallback(Callback)}.
*
* @see #setView
* @deprecated Custom toast views are deprecated. Apps can create a standard text toast with the
* {@link #makeText(Context, CharSequence, int)} method, or use a
* <a href="{@docRoot}reference/com/google/android/material/snackbar/Snackbar">Snackbar</a>
* when in the foreground. Starting from Android {@link Build.VERSION_CODES#R}, apps
* targeting API level {@link Build.VERSION_CODES#R} or higher that are in the background
* will not have custom toast views displayed.
*/
@Deprecated
@Nullable public View getView() {
return mNextView;
}
I found this exception randomly while testing my app and I am using toasts on a lot of places, it turns out I am running the app on a device with api 25, and you library seems to be the way forward.
Is it possible to provide a code from which I could reproduce this issue?
Was this issue that this library handles ever been fixed?
If so, from which version?
7.0之后通过Toast params设置动画有兼容方案么?
It says this:
Your project has set `android.useAndroidX=true`, but configuration `prodDebugRuntimeClasspath` still contains legacy support libraries, which may cause runtime issues.
This behavior will not be allowed in Android Gradle plugin 8.0.
Please use only AndroidX dependencies or set `android.enableJetifier=true` in the `gradle.properties` file to migrate your project to AndroidX (see https://developer.android.com/jetpack/androidx/migrate for more info).
The following legacy support libraries are detected:
prodDebugRuntimeClasspath -> me.drakeet.support:toastcompat:1.1.0 -> com.android.support:support-annotations:27.1.1
Please update the library so that we won't need this flag anymore.
just use a Application context ,and BadTokenException never happens.
here is the best prectice for toast
https://github.com/hss01248/Toasty
I need to dismiss toast before 2 seconds.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.