Changes in Android 11 (API 30)

1. Background custom Toast is prohibited

Updated status of different Toast types at different app modes

Custom Toast CANNOT be shown when app is at the background. A Toast with message “Background custom toast blocked for package [packageName] See g.co/dev/toast.” is shown instead.

illustration of customised toast when app is in the background

On the other side, normal text toast can still work as usual:

illustration of text toast when app is in the background

2. Customisation is not allowed at text Toast

illustration of customised text Toast in API 29 or older

Before Android R, both simple Toast and text Toast can be customised with the margins and gravity with offsets. However, starting from Android R, text Toast can no longer be set with these parameters since the setter functions have become no-op functions, i.e. a function can be called but do nothing. See below for the screenshots of the setGravity official documentation.

Screenshot of setGravity documentation from this link

However, this new implementation is only applied to text Toast only. In other words, the simple Toast , which is constructed by Toast(context: Context) can still be customised with margins and gravity with offsets. See below for the illustration:

illustration of custom simple Toast at Android R

3. Deprecated function — setView()

setView() official documentation showing the function is deprecated in Android R

Although it is still allowed to customise the Toast view by setView(view: View) , it is actually a deprecated function in Android R.

“Deprecated” means the function can still be used at the current moment but it is probably going to be removed in the future Android version. Developer is recommended to avoid using this function for long term development.

4. Newly added callback — Toast.Callback