Reputation: 4201
I use Toast dialogs a lot throughout my application. However, I have noticed that after switching activities, the dialog will continue to stay visible until its timer has run out.
Toast.makeText( getApplicationContext(), R.string.toast_need_bt, Toast.LENGTH_LONG ).show();
I use Toast.LENGTH_LONG
because the message is long and if the user decides to read it, the longer time option is needed. However once the user has used the application once or twice they will not need to read the toast messages and they will quickly move from activity to activity. However, these toast dialogs stay on the screen even while switching from activity to activity.
Is there a way to end all Toast Dialogs if the current Activity is terminated?
Upvotes: 0
Views: 790
Reputation: 11191
Toast.makeText
returns a Toast
object. Call cancel()
on this object to cancel it.
Check this post for more answers on this topic How to cancel Toast
Upvotes: 1
Reputation: 12477
Even though there are a few answers already on how to use the .cancel() method, i would like to add a few options to this usecase:
1) Create in layout notifications Cyril Mottier's Article here
2) Display the toast only the first X times
3) Create a dialog with a "Show notifications" checkbox to allow the user to opt out.
Upvotes: 1