Frage

in my Android app I have a native code that runs on separate thread, it use a while loop. The native code send data periodically to backend server using HTTP GET method. Now, I need the native code to also "send" data to my main Java UI thread.

My question is, how can I send some kind of an event or signal, that can be captured by the main Java UI thread, so that it knows when to perform some kind of action (updating the UI)? I know I can use JNI to call native code from Java side, but I do not know how to perform similar thing from native side to Java side.

Thanks guys!

War es hilfreich?

Lösung

You can call any Java method from your native code as described here. In your case you'll need to use Activity's runOnUiThread() inside that method to run your code on the main thread.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top