I use this code in all my app fragments and it should be better if I use a static method. How can I do it? This static method should also works on fragment, not only activities.
My not static showToast method:
public void showToast(String msg){
Toast.makeText(getActivity().getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}
SOLVED BY USING THIS STATIC METHOD thanks @KishanDhamat
public static void showToast(Context context, String text) {
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
}
This is my solution, hope it can help
Use this:
now for calling this method you should call like this:
Here classname is class that containing static method.
Context
as parameterstatic
Context
as first argument of yourToast.makeText
call