Executing native background work on Java threads
In previous sections, we used the JNI interface to execute native functions on the main thread. Since they run on the main thread, the functions were able to update the UI, access the Activity
instance fields, and or update any UI widget directly.
However, as we discussed before, for long computing or intensive tasks we have to execute them on the background thread.
In previous sections, we learned how to use the AsyncTask, Loader
, Handler
, and Remote Services to execute work on background threads that don't reduce the UI responsiveness or interfere with UI rendering.
In any of these Android specific constructs, the background thread is already attached to the JVM. Hence, the background thread already possesses access to a ready to use JNI environment.
In our next example, we will make use of the Loader
construct and build AsyncTaskLoader
, that loads an image on the background, converts the image to gray scale in native code, and publishes...