I am trying to execute depending on the environment, in a previous question I was raised to use polymorphism as you can see in the following question . The problem I have is that in the android environment I need to execute the command getApplicationContext (), where I require it in the android environment only, the issue is that when I run the class in windows, I can not compile because the command is not recognized but is for the platform that was made. Then the idea that came up is in the android project, only the class that is for android will be included. The problem that arises is how to execute one class or another, depending on the environment. Here is an example I have in the project the breeding class of the question quoted, "Trimmed"
public class reproductor implements Runnable {
static reproductor getInstance() {
//System.out.println("bfhsoftware.sonidoambiental.reproductor.getInstance()");
if (main.isandroid()) {
System.out.println("reproducir android");
//return new Class.forName("bfhsoftware.sonidoambiental.Sonidoambiental");
return new ReproductorAndroid();
} else {
System.out.println("reproducir java");
return new ReproducirJava();
}
}
}
Desktop class
public class ReproducirJava extends reproductor {
}
In a subproject I have the following class Android class
public class ReproductorAndroid extends reproductor{
}
obviously in the sub-project the classes of the main project are included and can be used, but otherwise when referring from the main project to a class that is outside the project, in this case the android sub-project, not I know how to call her, and here's the question. in this example it is visible that I call the PlayerAndroid class but being out of the project gives an error, the reason why I have to remove it is because of the aforementioned command, which runs only in the android environment, outside of this there is no function. For this and other reasons I need to place some extends classes of the main project, but I do not know how to call it, could someone help me? Explain me clearly enough?