WxAndroid/WXNative

From WxWiki
Jump to: navigation, search

About

WXNative contains static native functions declarations that are used in WX Java classes. Each time something happens in Java and wxWidgets should know about it, native function is required. All these native functions are found in wx/android/private/native.h and wx/android/jni/native.cpp for definitions.

While native function use may differ depending on class, its most commonly used for events. Since wxWidgets cannot know that certain thing occurred without receiving that information directly from Java class.

Adding new native method

Following coding guidelines all native functions should go in native.h and native.cpp in CPP and WXNative.java in java. They should all be public static native and should contain prefix "wx" e.g. public static native wxStart(). Within java they are accessed via WXNative class. Example is WXNative.wxStart();. Since WXNative is both public and static it can be accessed when ever from any class.

CPP

In CPP all native functions must follow following naming convention:

jtype Java_org_wxwidgets_WXNative_methodname(JNIEnv* env, jclass thiz, other arguments)

  • jtype - Return type of function declared in Java, if method's return type is "int" then his jtype is jint. Any kind of object in java is returned as jobject.
  • methodname - Name of method, for previously given example methodname was "wxStart".
  • otherarguments - All arguments declared in Java must be placed here with cooresponding jtype(int - jint, string - jstring, any object - jobject, ...).