I have been struggling with this problem for two days,I am in situation where i need to use a method in ActivityB
from ActivityA
. The problems lays in getting the context of A i have tried many solutions like:
static ActivityA activityA;
In onCreate
state:
activityA = this;
and add this method:
public static ActivityA getInstance(){
return activityA;
}
In ActivityB
, call
ActivityA.getInstance().myFunction(); //call myFunction using activityA
it did not work out because this need the ActivityA
to be instantiated in order to pass its context to A but this is not accomplishable in my case is there any way of getting an activity's context without switching activities .
my question might turn out to be simple or intuitive but im new to this concept , thanks in advance