6

Recently my smartphone (Google Pixel 3) got an update from Android 11 to 12. Afterwards, I wanted to adapt my app Sensor Recording accordingly. So I made some changes in "build.gradle":

compileSdkVersion 31    // 30 before
defaultConfig {
    targetSdkVersion 31    // 30 before
    …
}
dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.0'         // 1.3.1 before
    …
}

Everything was working correctly. However, I detected that the Toast messages were different now: They include a useless icon, and – even worse – the text message was truncated.

Before – with SdkVersion 30

enter image description here

And after – with SdkVersion 31

enter image description here

Both Toast are generated with the same code. But in the new version, the important parts of the text are missing. How can I get back the old Toast behaviour?

  • 4
    From the docs: `If your app targets Android 12 (API level 31) or higher, toast is limited to two lines of text and shows the application icon next to the text. Be aware that the line length of this text varies by screen size, so it's good to make the text as short as possible.` You can use `Snackbar`. – Darshan Dec 10 '21 at 17:11
  • I get a lot of stack traces on Toast messages in Android 12 especially when there are many. However, the Toast still displays (as described above). – Brian Reinhold Feb 07 '22 at 23:04
  • Did you find solution? please share here. – Manoj Apr 20 '22 at 12:40
  • Not really! But as a workaround, I have replaced the "Toast" calls with invocations of "Snackbar", as recommended above by DarShan. – Michael Braun Apr 21 '22 at 17:36
  • You'll find a some code to make snackbars multi-line in my answer here https://stackoverflow.com/questions/70370186/why-do-toasts-get-truncated-when-app-is-installed-on-android-12-api-31/73132986#73132986 – Michael Alan Huff Aug 25 '22 at 23:31
  • This is the expected behavior's of the native Toast message Android 12 onwards as @Darshan has mentioned. To get the previous Toast behaviour, you can use custom view for the Toast message, Please refer this example https://stackoverflow.com/a/11288530/1633297 – Nishara MJ May 11 '23 at 11:49

0 Answers0