-1

I have more than 3 Activity but let's just take three of them, BaseActivity, Splashscreen, MainActivity. Splashscreen and Mainactivity extends BaseActivity. Now i am showing a Snackbar inside the BaseActivity whenever I get failureresponse from the server. The response code is in BaseActivity and parallely i am transitioning from splashscreen to MainActivity.

The snackbar is not showing up? What could be the error? is there a way to make static snackbar? i have tried it but didnt get the getWindow from a static method? Anyone faced this problem?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Aman Verma
  • 3,155
  • 7
  • 30
  • 60

1 Answers1

0

Yes you can create a static method in your utils and create snack bar in utils class and use anywhere in your app

     public static void showSnackBar(View view, String msg) {
        if (view != null) {
            Snackbar snackbar = Snackbar.make(view, msg, Snackbar.LENGTH_LONG);
            View snackbarView = snackbar.getView();
            TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
            textView.setMaxLines(5);
//snackBarView.setBackgroundColor(Color.argb(255, 8, 20, 37));
            snackbar.show();
        }
    }

Use:

Utils.showSnackBar(getView(), failureMessage);
Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33