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

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -