java - Context having reference to class in android -


hi trying understand use of context though couldn't. following program using context. question significance of " context = class.this " ?

class public vcardactivity extends activity    {    string vcard = "vcard";    context context;    }    public void oncreate ( bundle bn )    {      super.oncreate(bn);     setcontentview(r.layout.main);     context = vcardactivity.this;    } 

your current code doesn't show use of context. shows activity context.

textview sometext=new textview(context); 

this code of mine shows, passing context constructor of textview in order make object. reason is, object needs know information, state of current context, , reason why many views, classes, helpers needs context.

 context = vcardactivity.this; 

in code having activity object assign context context. works because activity class inherits context , many classes needs context create it.


Comments

Popular posts from this blog

pentaho - Carte Status / Kettle Slave Server Status page shows status for random runs instead of the latest run -

R summary function in ddply (plyr) in a simple way -

c# - Are delegates created via lambda expressions guaranteed to be cached? -