android - Context in EnableListAdapter -


i have created expandablelistadapter class , need send context activity accessing it.

myactivity.class:

menuexpandablelistadapter.useinstancecontext(getapplicationcontext()); 

myexpandablelistadapter.class:

static context context; public static void useinstancecontext(context applicationcontext) {     context = applicationcontext; } 

the above code works, works:

menuexpandablelistadapter.useinstancecontext(this.getapplicationcontext()); 

what's difference? way pass context? i'm still trying understand context.

context necessary in order access resources , other things. so, both - application , activity contexts work. practice tight smallest thing, works, activity in case. so, suggest new way you:

menuexpandablelistadapter.useinstancecontext(this); 

also, in example, there no difference between calls. this reference current object.


Comments