alexis,
@alexis@foxgirl.land avatar

i finally found something that even mentioned passing a callback from native code to java via jni. i'm still not entirely sure if this is the best or only path to pass callbacks to java. the types of functions i'm planning on passing as callbacks are:

the page mentioning the callback is https://stackoverflow.com/a/1391240

pub fn positive_button_function() {
    info!("Positive button pressed...");
}

or

|| {
    info!("Positive button pressed...");
}

anyone have any suggestions on how to implement this?

zombierustpunk,
@zombierustpunk@hachyderm.io avatar

@alexis one thing that i’ve done that worked okay was, instead of using a lamdba, I would have an object, and I would pass a pointer to the object into java as an int. Then the java could call into a known c++ function that could take the int and cast it back to a pointer and call the method on it with the other arguments.

the trickiest part is if the callback is “escaping”, then you might need some bookkeeing to manage the lifetime of the pointer

zombierustpunk,
@zombierustpunk@hachyderm.io avatar

@alexis it’s really hard to describe something like that within hachyderm’s character limit 😓

alexis,
@alexis@foxgirl.land avatar

@zombierustpunk thanks! i'll have to look into it. i've also posted a question about this to the people who made the jni crate to see if they'd help, but in the meantime, i could see if this works. https://github.com/jni-rs/jni-rs/issues/533

zombierustpunk,
@zombierustpunk@hachyderm.io avatar

@alexis oh, somehow i missed that it was rust. i’ve only used JNI with C++.

i’d be curious to know what you end up with. i might even play around with it some myself

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • anitta
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • megavids
  • JUstTest
  • All magazines