I don't really get the idea behind how this whole thing works really, so if I have some class A
that need the context of a class B
which extends Activity
, how do i get that context?
I'm searching for a more efficient way than giving the context as a parameter to class A
constructor. For example if class A
is going to have millions of instances then we would end up having millions of redundant pointer to Context
while we should be able somehow to have just one somewhere and a getter function...
Ok, I will give a small example on how to do what you ask
public class ClassB extends Activity
{
ClassA A1 = new ClassA(this); // for activity context
ClassA A2 = new ClassA(getApplicationContext()); // for application context.
}