Skip to content Skip to sidebar Skip to footer

Android Display Toast Even The App Is Closed

Say, I have to calculate the sum of two digits and I pass the two values to the server and sever returns the calculated value and the app displays it in a Toast. It works perfectly

Solution 1:

Showing toasts when your application isn't in the foreground even if possible is not the best idea. This is because a Toast poppoing out of nowhere can be annoying, uninformative and disrupt whatever the user is currently doing.

As you mentioned, Notifications are the way to go on this one. A notification can be read by the user whenever he decides to do it and they can't be missed as opposed to Toast simple because checking the notification requires the user to take action.

You can read more on notifications and how to implement them HERE.

Solution 2:

It is not possible to show a Toast when you close the app. But you can show it even when you move the task to the background. For ex, if you have Titanium Backup installed on your device, open it and press the back key immediately. You can see the toast on the home screen. Notification is a better way to go. Although you have to bring the notification bar down to see the result. But if you do want a toast to be displayed, send the task to background.

Solution 3:

I'm a little confused as to why you would need a server backend to calculate the sum of just two digits, but I'll answer anyways.

Yes, you can show a toast even if your app isn't in the foreground. However it must be running in the background. It is not possible to show a toast if your app's process is terminated. You can use both the application context or an activity/service context to display a toast.

However, in this case you might want to use a notification to provide a better user experience. Users find it hard to near impossible to tell from which app a toast has originated, as it is just some text flashing on the screen with no identification. However, you can easily tell the user which app your notification belongs to. Also, by using a notification you do not force the user to read your text at the instant the toast exists. Instead, the user may view the notification whenever he has time.

Post a Comment for "Android Display Toast Even The App Is Closed"