I've seen here and here that you cannot override native methods in android, but I was wondering if I can have a class declaring some native methods, and then extend it with another class declaring some additional native methods.
My situation is as follows:
public class A{
public native int aMethod();
}
public class B extends A{
public native int bMethod();
static {
try{
System.loadLibrary("MyNativeLibraryWithBothaMethodAndbMethod");
}
catch (java.lang.UnsatisfiedLinkError e){
System.out.println (e);
}
}
}
public class MyActivity extends Activity {
private B bClass;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
bClass = new B();
bClass.aMethod();//Working fine
bClass.bMethod();//UnsatisfiedLinkError
}
}
The library is loaded without problems, and the first method is called, but not the second.
If I move the bMethod from B to A, everything works fine.
Moving the System.loadlibrary() from B to A seems to have no effect.
Is it possible to extend A class with additional native methods?