1

I used to call the show() method on a created toast every 1s during a few seconds, to obtain a toast that stays on screen for more than LENGTH_LONG.

(Similar to Android SDK keep Toast from fading away)

Note: the toast text is periodically changed while it's being displayed.

Unfortunately, it does not work anymore with Android 8.0: the toast now disappears after approximately 4s. It looks like only the 1st call to show() is working, and all subsequent calls have no effect.

I understand that it is not the intended behaviour of a Toast to stay on-screen, but before moving to another solution, I just wanted to check if this is an expected behaviour of Android 8.0 ? Maybe related to the Toast overlay attack vulnerability ?

TagadaPoe
  • 95
  • 8

2 Answers2

0

Android has taken steps to prevent malicious toast overlay that can trick users into granting unnecessary permissions or running other unwanted code. So it makes sense that a persistent icon is prevented from being shown.

However, I have also come across a SO question regarding an undesired text "blending effect" in Android Oreo Toast discussed here.

Therefore it seems that at some point Oreo has allowed for subsequent immediate Toast calls and it may not be the default behavior just yet.

Jantzilla
  • 638
  • 1
  • 7
  • 19
0

Since Android 7.1.1 each non-system package can only queue one Toast at a time. See the commit:

https://android.googlesource.com/platform/frameworks/base/+/4ee785b698211b5ccce104e226b073ffbb12df55

Furthermore, even if you bypass the Toast mechanism and add TYPE_TOAST window directly, you will end up with a "bad token exception" if you add a TYPE_TOAST window more than once at a time. This is to enforce the policy that toast windows can only be displayed for a limited time (3.5s to be precise).

https://android.googlesource.com/platform/frameworks/base/+/dc24f93%5E%21/

(Note the changes to WindowManagerService.java. A return of WindowManagerGlobal.ADD_DUPLICATE_ADD causes exception to be thrown at an upper level)

So yes, the behavior is intended.

headuck
  • 2,763
  • 16
  • 19