Suppose i have an interface class:
public interface interfaceClass{
void message();
}
The interface is implemented by two Activities A and B:
public class A extends AppCompatActivity implements interfaceClass{
@Override
public void message() {
// message: this is class A implementing interface
}
}
public class B extends AppCompatActivity implements interfaceClass{
@Override
public void message() {
// message: this is class B implementing interface
}
}
Now I have service where i want to call the method of the interface class implemented by both activities A and B by creating the object of the interface class but i don`t know how to initialize the interface class object in order to call the method implementation from class A or B
public class serviceClass extends Service {
interfaceClass object = (interfaceClass)context;
object.message();
}
Any suggestions how to get the context of the activity A or B to initialize the object???