Run native code in background
android, android-ndk, native, opencv
Solution
I look around and found that native code is only available to be run as activity
No. Any Java class can have native methods in Android. You can have a background worker thread, implemented either as a `Thread`-derived class or as a `Runnable`, which would do the background work by calling native method(s).
pthreads are another possiblity, but those threads are invisible to the Java subsystem; you might want to call Java code from the worker thread - at the very least to pass something back to the UI thread. It's easier if the worker thread was started in Java in the first place.
For the record, Android services are not threads. They run on the main thread. Threads can be started from a service, but they can be started from an activity as well. Thread's lifetime is up to you.
The NativeActivity stuff is for having completely Java-less apps. You don't have to follow that way.
Problem
I made an image processing application using OpenCV and Android NDK. Now, I want to display the result in my main activity which is the dashboard containing some data and graphs based on the native image processing application. I look around and found that native code is only available to be run as activity (NativeActivity class), which is my approach currently where the main activity is replaced by blank screen of the native activity reference#1. My questions are, is this true? How can I run my native code from the main activity while keeping the main activity active in foreground and the native code run in background? Thanks guys!