Android Question Can't show toast message with app in background (api 34)

Sandman

Expert
Licensed User
Longtime User
This post started as a question, but I found the answer before saving so I'll leave it here as info for the forum. :)

Just like the title says, I'm not getting any toast messages from my app when it is in the background when I test this on a device with api 34.

SOLUTION: You need the notification permission for that with this api level. If you don't have this permission, nothing is shown.
 

Sandman

Expert
Licensed User
Longtime User
Yep, I have. I've done several tests, and for me it seems to be a rock-solid connection between being able to show toasts from the background and having the notification permission.

Are you getting different results?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Follow-up: At another place in my test app I had a notification. Just to test that I hadn't made a mistake somehow, I removed that notification code.

When I ran the app again, no toast did display, just as before. But when I went into the app settings to enable the notification permissions it said that the app doesn't use notifications, so I couldn't enable it. Bottom line is that I can't make the toasts display now.

Weird stuff. I feel like this should be documented in the Android docs but I was only able to find these two pages, which doesn't mention anything about it:
- https://developer.android.com/guide/topics/ui/notifiers/toasts
- https://developer.android.com/reference/android/widget/Toast

Both pages make me feel like Google is trying to steer us away from toasts.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
"Note that Snackbars are preferred for brief messages while the app is in the foreground.

Note that toasts being sent from the background are rate limited, so avoid sending such toasts in quick succession."

Really Google, Snackbars what next???
 
Upvote 0
Top