Android NDK Callbacks to Java Activity -
Android NDK Callbacks to Java Activity -
i'm porting application of mine bulk of work done within native part of application , java side purely ui.
what i'm trying implement @ moment progressbar show status of native thread's operation. ui consists of different activities , i'm intending display progressbars activities.
the question is: how do it? have native code follows:
jclass clazz = emv->findclass( "com/example/myapp/mainactivity" );
that returns null clazz. realised no mainactivity activity beingness displayed @ time - instance of settingsactivity, tried changing above line accordingly still returned null.
is not possible phone call findclass() native code retrieve activity class?
ultimately think need phone call method such below:
public void progressupdatefromnative( int ) { runonuithread( new runnable() { @override public void run() { displayprogressupdate(); } } ); }
..and method within 1 of activities.
jmethodid progressupdatefromnative = env->getmethodid( clazz, "progressupdatefromnative", "(i)v"); env->callobjectmethod( g_pobj, progressupdatefromnative, 1 ) ;
i have retrieved javavm pointer onload() jni phone call , called javavm->attachcurrentthread() retrieve env pointer used above.
can please tell me i'm missing - ie -why getting null class returned findclass, or set me on different track if doing wrong. intended read on handlers don't think far through in understanding yet.
note: realise poll native variables java ui prefer callback/event handling implementation rather polling.
if code not invoked java method utilize scheme classloader in findclass()
knows android scheme classes.
i suggest using getting reference class in jni_onload
, creating global reference via newglobalref
, passing threads or storing in global variable.
more info behavior: http://markmail.org/message/25rrwp4va443rjuk#query:+page:1+mid:2u5wlkjyugwp75qa+state:results
java android callback android-ndk native
Comments
Post a Comment