Why Toast.makeText and not new Toast

Viewed 3839

This is may be a noob question, but I was wondering why do we have to use a static method (makeText) to create a Toast and not a constructor.

Why do we have to use this:

makeText(Context context, CharSequence text, int duration)

instead of this:

new Toast(Context context, CharSequence text, int duration) 

This is the makeText method:

    public static Toast makeText(Context context, CharSequence text, int duration) {
        Toast result = new Toast(context);

        LayoutInflater inflate = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
        TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
        tv.setText(text);

        result.mNextView = v;
        result.mDuration = duration;

        return result;
    }

Why don't we have the following:

public Toast (Context context, CharSequence text, int duration) {
    this(context);

    LayoutInflater inflate = (LayoutInflater)
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
    TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
    tv.setText(text);

    this.mNextView = v;
    this.mDuration = duration;
}

I searched the web and source code for any reason but I didn't find.

Please if you have an idea, don't hesitate.

3 Answers
Related