android - Using "getBaseContext" Or "this" when using Toast to display Messages -
i having button laid out in linear layout on activity .
when clicked on it, message appear on screen using toast class
two methods works fine me
first 1 :
private void displaytoast(string msg) { toast.maketext(getbasecontext(), msg, toast.length_short).show(); }
and second 1 :
private void displaytoast(string msg) { toast.maketext(this, msg, toast.length_short).show(); }
my question deference between getbasecontext()
, this
,and when should use getbasecontext()
, when should use this
??
your activity context, use directly this
.
keep getbasecontext
special cases activity not reachable directly.
Comments
Post a Comment