I'm facing an issue which hopefully you can help me to fix. In my Android app, I display a Snackbar using the usual way (Snackbar.make().show()). However, I also have to deal with configuration changes (like orientation changes from portrait to landscape).
Now if the configuration changes, the Snackbar disappears, which is nothing I wouldn't expect. I had the same issue with ProgressDialog and AlertDialog, which I solved by using a custom subclass of DialogFragment.
I also had this issue with my AsyncTasks which I solved by using a custom subclass of Fragment which I retain (setRetainInstance(true) in onCreate() of the Fragment) and which keeps a reference to my AsyncTask. In both cases, each Fragment has a callback interface which the Activity has to implement and I set/unset the callback during onAttach()/onDetach().
However, Snackbar seems to be different because it is attached to a View instead of a Context like for example the ProgressDialog (in getDialog() of my DialogFragment I can use new ProgressDialog(getActivity())).
So when and how shall I display a Snackbar after a configuration change? Is using a Fragment the way to go or should I try to work around this by having some private variables on my Activity which I save/restore via the savedInstanceState? I hope you can help me. Thank you in advance.
Since no suitable answer was provided and I had to meet a deadline, I now went with the following solution: