Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to hide Android toast when app in background

Tags:

android

toast

If I issue a toast when my App's activity is not in the foreground then the toast will still show up on the screen. How can I prevent my toast from showing up when my app is running in the background. i.e with none of its activities currently the activity being shown.

I am thinking that I must somehow detect that my activities are not the activity currently being shown and when true not issue any toasts; but how would I detect this condition?

Thanks

like image 957
w.donahue Avatar asked Jan 20 '11 02:01

w.donahue


1 Answers

Set a flag when your app is in the background (i.e. in onPause), and don't send out toasts if the flag is set.

If you have tons of activities, you can define your own Activity base class that wraps this functionality.

like image 153
EboMike Avatar answered Sep 30 '22 14:09

EboMike