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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With