The second Android 11 Developer Preview is now available, test it out and share your feedback.

Updates to toasts in Android 11

Android 11 protects users by deprecating custom toast views. To give developers more time to adapt to these changes, they take effect only if your app targets Android 11.

Custom toasts from the background are blocked

For security reasons and to maintain a good user experience, the system blocks toasts that contain custom views if those toasts are sent from the background by an app that targets Android 11. Note that text toasts are still allowed; these are toasts created using Toast.makeText() that don't call setView().

If your app tries to post a toast containing a custom view from the background anyway, the system doesn't show the message to the user. Instead, the system does the following:

  1. Displays the following toast message:

    Background custom toast blocked for package package-name. See g.co/dev/toast.

  2. Logs the following message in logcat:

    W/NotificationService: Blocking custom toast from package <package> due to package not in the foreground

Toast callbacks

If you want to be notified when a toast (text or custom) appears or disappears, use the new addCallback() method.

Text toast API changes

As a result of the platform behavior change, apps that target Android 11 see the following side effects for text toasts: