Question

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?

Était-ce utile?

La solution

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");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top