Android - Snackbar vs Toast - usage and difference
Asked Answered
S

9

151

We have been using just Toasts in our application so far and as we are planning to adopt some new features from Support Design Library I am wondering what's the recommended usage for Snackbar vs. Toast.

I have been reading on the google material snackbar doc.

Snackbars provide lightweight feedback about an operation in a small popup at the base of the screen on mobile and at the lower left on desktop. They are above all over elements on screen, including the FAB.

and toasts.

Android also provides a capsule-shaped toast, primarily used for system messaging. Toasts are similar to snackbars but do not contain actions and cannot be swiped off screen.

I understand what they do but I am a bit confused when to use what. Does it mean that:

  • If I don't require user interaction I would use a toast?
  • What is meant by "system messaging"? Does that apply to displaying information when something important happened between my app and the Android system?
  • What I like is the swipe off screen feature - would that be a reason to start replacing toasts with snackbars? (this is a bit opinion based question though)
Sandry answered 23/12, 2015 at 9:25 Comment(0)
C
143

If I don't require user interaction I would use a toast?

You can still use Snackbar. It is not mandatory to have an action with Snackbar.

What is meant by "system messaging"? Does that apply to displaying information when something important happened between my app and the Android system?

I believe this means that Toasts are to be used if there are some messages pertaining to the system. Either android as a whole or some background service you may be running. E.g. Text-To-Speech is not installed. OR No Email client found.

What I like is the swipe off screen feature - would that be a reason to start replacing toasts with Snackbar? (this is a bit opinion based question though)

That is one reason. But there are several other plus points. For an example: Your toast remains on screen even when the activity is finished. Snackbar doesn't. There is less confusion if the toast does not popup (or keep popping up in case of multiple Toast creation in sequence) long after the app is exited. This will not happen with Snackbar.

More than everything: I suggest if you are thinking, you should switch. SnackBars look far better than Toasts.

Cana answered 23/12, 2015 at 9:35 Comment(4)
Cheers, the point with Snackbar being alive only while you are on the activity is really useful.Sandry
I would add that Toasts are preferred for messages that refer to the app as a whole in addition to system messages, while Snackbars are preferred for messages that refer to the current activity. For example if your app checks for updates on launch, it's best to use a toast for the result message. If your app has items that can be deleted, its preferred to show the deleted response message as a snackbar with an undo button.Baste
One other thing to note is that toasts are not displayed when notifications are turned off.Burns
Also important difference is that only one Snackbar is shown at any time, unlike the Toast - you can have multiple Toasts shown on top of each other, which can be annoying for the user, especially considering the fact that they can't be removed by swiping.Coition
S
79

I would like to add a small comparison between toast and snack bar. In my opinion if your intention is to present a warning or info that need user interaction/acknowledgement, you should use a snack bar. If it is just an info message that doesn't need any user acknowledgement you can use toast.

# Toast Snackbar
1 Can't be dismissed by swiping Can dismiss by swiping
2 Activity not required (Can show in android home or above other apps) Can show inside an activity of your app
3 Can't handle user input Can handle user input
4 Good for showing info messages to user Good for showing warning/info type messages to user that needs attention
Sortilege answered 24/12, 2015 at 18:37 Comment(0)
L
39

Toast:

  1. Toast was added in API Level 1
  2. Basically Activity is not required (Can be shown on Android home or even above other apps)
  3. It can’t perform an action based on User input
  4. It can’t be dismissed by swiping
  5. It can’t handle user input like Swipe, Click etc.
  6. Good for showing info messages to user

SnackBar:

  1. SnackBar was added in API Level 23
  2. It can be showed inside an activity of the Applications
  3. It can perform an action
  4. It can be dismissed by swiping
  5. It can handle user input
  6. Good for showing warning/info type messages to user that needs attention

Usage of SnackBar and Toast:

SnackBar:

SnackBar can be used in the areas where a simple popup message needs to be displayed along with an option to perform action. For Example: In GMail application, when you delete Mail, quick SnackBar display at the bottom with Message ‘1 Deleted’ with an action button ‘Undo’. On pressing the ‘Undo’ action button, the deleted mail will be restored.

Toast:

Toast can be used in the areas where System messages need to be displayed.

For Example:

When your App tries to download JSON from remote server but it fails due to Server Timeout or No resource found, you just need to display the error message saying that ‘Error Occurred’. But understand the Toast message cannot be dismissed by swiping. If you still want to have the capability of dismissing it in your App, go for SnackBar.

Lise answered 4/3, 2016 at 12:2 Comment(0)
M
21

According to the official documentation at Pop-up messages overview:

Note: The Snackbar class supersedes Toast. While Toast is currently still supported, Snackbar is now the preferred way to display brief, transient messages to the user.

and (Material Design) Snackbars's documentation:

Related concepts: Android also provides a Toast class with a similar API that can be used for displaying system-level notifications. Generally, snackbars are the preferred mechanism for displaying feedback messages to users, as they can be displayed in the context of the UI where the action occurred. Reserve Toast for cases where this cannot be done.

Maryjanemaryjo answered 14/11, 2018 at 15:38 Comment(0)
F
7

Difference between Toast and Snackbar Android

  • Toast messages can be customized and printed anywhere on the screen, but a Snackbar can be only shown in the bottom of the screen.
  • A Toast message doesn’t have action button, but Snackbar may have action button optionally.
  • Toast message cannot be off until the time limit finish, but Snackbar can be swiped off before the time limit.
  • You can set how long the message will be shown using this three different values.
    Snackbar.LENGTH_LONG
    Snackbar.LENGTH_SHORT
    Snackbar.LENGTH_INDEFINITE

Usage

Toast

Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_SHORT).show();

Snackbar

Snackbar snackbar = Snackbar.make(view,"This is Simple Snackbar",Snackbar.LENGTH_SHORT);
snackbar.show();
Forrester answered 30/7, 2020 at 11:24 Comment(0)
D
2

Google's Material Design Specification says that it's ok to have a Snackbar without an action. They have provided examples of what a Snackbar should look like if it only displays a single String. I would assume that "System Messaging" means device events like network connection being lost - whereas archiving an email is a Gmail specific action, for example.

For consistency's sake, it makes sense to pick either a Toast or a Snackbar, and apply that throughout your app.

Deoxyribose answered 23/12, 2015 at 9:35 Comment(0)
B
1

The short answer is that those are 2 ways to communicate things to the user that happen in the background, and you can peak one of them, they both fine. Just make sure you're using the same one and not switching between them back and forth.

The long answer:

  • No, that's mean that if you need some action you must use Snackbar. You can still use Snackbar only for messages (like "Uploading finished").
  • By "system" it doesn't mean just Android system. For example- if there was a json parsing problem while getting info from your server you can still use toast to let the user there was a problem while communicate with the server.
  • If you really need to swipe this off, that absultly be a reason to pick Snackbar
Bonzer answered 23/12, 2015 at 9:39 Comment(0)
H
1

Our design team is looking at using either toasts or snackbars as well. We come to a conclusion that the app should be using snackbars given the flexibility of it.

Toasts should only be used when we need a persistent, short string, info message that still make sense across different screens.

Husserl answered 9/10, 2016 at 23:43 Comment(0)
E
1

Android also provides a capsule-shaped toast, primarily used for system messaging.

I think with "system messaging" they also refer to the fact that a toast will be shown for a specific time and can not be dismissed even if the user navigates across activities and even if the app is moved to background.

I consider it an advantage of snackbar to limit its scope to an activity and to be able to dismiss it.

Equiangular answered 21/11, 2018 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.