Save state of Snackbar after changing orientation

Viewed 670

I want to save the state of Snackbar after screen rotation. I can't find any default implementation, like onSaveInstanceState() and onRestoreInstanceState(...) of LayoutManager.

The only way that I see is to keep boolean show***Snackbar variable and save/restore it. Any better solution?

1 Answers

Seems there are no easy way to do this if you are using the native library component. You will have to do this manually.

  1. Create a Parcelable model to represent the Snackbar instance.
  2. OnPause() create the Parcelable and save in the bundle.
  3. OnResume() recreate the Snackbar using the details in the bundle.
Related