3

I have a very simple Toast shown under certain circumstamces:

if (!this.isFinishing()) {
    Toast.makeText(this, R.string.my_toast_message, Toast.LENGTH_LONG).show();
]

Most of the times the Toast is shown and fades away as supposed but sometimes remains always visible and even if you terminate the App the Toast doesn't disappear.

This is a problem that occurs sporadically but when It happens It is very annoying and the only way to make the Toast fading away is rebooting the system or doing whatever thing that could show another Toastof whatever App.

This looks like a problem of Android itself rather than App since I have seen this issue happening on different devices and different Apps that use Toast.

I'm wondering if there is some workaround to prevent this issue.

AndreaF
  • 11,975
  • 27
  • 102
  • 168

2 Answers2

0

Toasts are meant to be system level notifications, so they won't disappear even if the app is killed. If you call show for several toasts they will show one after another. If the same toast is called multiple times, it'll give the impression that a toast will take a long time before fading away.

For app notifications, consider using Snackbars instead.

Please refer to this question.

Natan
  • 1,867
  • 13
  • 24
  • Unfortunately isn't an impression. The Toast doesn't go away at all when this issue happens. I have checked Snackbar and maybe I'm missing something but seems It needs a layout view passed in the constructor so doesn't seems as lightweight as Toast. – AndreaF Jun 28 '19 at 20:20
  • @AndreaF - Is it possible that you are calling the toast `show` in a loop? About Snackbar being more demanding, that is true: you should specify its parent view properly. – Natan Jul 01 '19 at 20:31
  • there is no loop – AndreaF Jul 02 '19 at 11:19
0

If you're creating the Toast in an asynchronous call, based on this answer, Toasts can get stuck when called from a thread that finishes and is killed before the Toast has a chance to disappear. If you're calling it in a separate thread, you may want to consider calling it from the main thread instead.

Cameron
  • 1,281
  • 1
  • 19
  • 40