Is there any way make Snackbar persist among activity changes?

后端 未结 6 980
一整个雨季
一整个雨季 2020-12-13 04:25

Although Snackbar is beautiful, it doesn\'t persist when changing activities. This is a bummer in scenarios where I would like to confirm that a message was sen

6条回答
  •  离开以前
    2020-12-13 05:11

    If I understand correctly, you do this:

    1. Activity A launch Activity B to send a message
    2. Once message is send, you display a confirmation message
    3. You go back to Activity A

    You can use SnackBar to do that by using an ActivityResult (here is a StackOverflow post with how to use it)

    Here are the steps:

    1. Activity A launch Activity B with startActivityForResult
    2. Do your stuff on Activity B
    3. Set your result (check the link above to understand)
    4. Finish Activity
    5. In Activity A, get that code in OnActivityResult and display your SnackBar with the proper message

    This allow you do display a Snackar in Activity A corresponding to result of Activity B.

    Hopes it can helps your problem

提交回复
热议问题