Run native code in the background

I made an image processing application using OpenCV and Android NDK. Now I want to show the result in my main action, which is a panel containing some data and graphs based on an application for processing my own images.

I look around and find that the native code is only available for activity (NativeActivity class), which is my approach at the moment when the main action is replaced by a blank screen of native activity link # 1 .

My questions, is that true? How can I run my own code from the main action, keeping the main asset active in the foreground, and my own code running in the background?

Thanks guys!

+4
source share
2 answers

I look around and find that the native code is only available to run as activity

No. Any Java class can have built-in methods in Android. You can have a background thread, implemented either as the Thread-derived class , or as Runnableone that would do the background work by calling its own method (s).

pthreads is another feature, but these threads are invisible to the Java subsystem; you can call Java code from a workflow - at least to pass something back to the user interface thread. This is easier if the workflow was launched in Java first.

Android - . . , . .

NativeActivity , Java. .

+4

Android pthreads . pthread_create() .

+2

Source: https://habr.com/ru/post/1524069/


All Articles