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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -