MrEngineer13 / SnackBar

toast-like alert pattern for Android inspired by the Google Material Design Spec

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Snackbar not showing when activity is resumed

mikesth007 opened this issue · comments

suppose i'm on Activity A then I show snackbar message it shows without any errors. then I call Activity B and come back to Activity A then the snack bar is not showing.

A => B => A ----> call show() not displaying anything...

Are you saving your SnackBar instance? via

@Override
protected void onSaveInstanceState(Bundle saveState) {
    super.onSaveInstanceState(saveState);
    // use this to save your snacks for later
    saveState.putBundle(SAVED_SNACKBAR, mSnackBar.onSaveInstanceState());
    }

@Override
protected void onRestoreInstanceState(Bundle loadState) {
    super.onRestoreInstanceState(loadState);
    // use this to load your snacks for later
    mSnackBar.onRestoreInstanceState(loadState.getBundle(SAVED_SNACKBAR));
}

Thanks. It works for normal Activity. But how would i achieve this while using an Abstract Activity class.

I have an Abstract class

public abstract class BaseActivity extends Activity
    {
        protected SnackBar snackbar;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            snackbar = new SnackBar(this);
        }

        protected void showInfo(String info)
        {
            snackbar.show(...);
        }

        protected void showError(String error)
        {
            snackbar.show(...);
        }
    }

Now I would like to extend this BaseActivity in all my activities.
Is it possible?? if yes, how can i achieve this?

No you cannot implement it like this. You need to initialize it in the class where you're going to use it