문제

I'm trying to create a static utility class which will contain simple functions like Messagebox(AlertDialog), EmailSender, etc... and will call these functions on other activites. But as I understand I can not create a static class if it is not in a class. What do you suggest for this kind of utility classes?

도움이 되었습니까?

해결책

Why not make it that way

class Utils{
    public static void makeToast(Context context, String text){
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }
}

In your activity call it this way

Utils.makeToast(this,"hi");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top