[Interest] [Android] Example code of running C++ code on UI thread

Ben Lau xbenlau at gmail.com
Mon Dec 23 01:54:23 CET 2013


Hi,

I am working on few Android projects that need the use of native
components(e.g WebView). However, the Qt 5.2 do not provide binding of
Android's view component and therefore it need to build by our team.

Override the QtActivity class is the most simple method , but it may be a
bad idea as it may not compatible for newer version. Moreover, it is not
reusable.

Now, I am trying to refactor the code to make some reusable components .
The first product is a class called QtAndroidRunner to execute C++ code on
the UI thread.

The source code with example code:
https://github.com/benlau/qtandroidexamplecode/tree/master/qtandroidrunner

This example project will create a WebView using native component on top of
QtSurface.

The solution isn't perfect , it need to be initialized on JNI_onLoad(). As
the FindClass function can only resolve custom Java code inside Qt project
on JNI_onLoad(). Although QAndroidJinObject is able to resolve custom Java
code outside JNI_onLoad(), it has no API to obtain the jclass object to
setup native methods.

Therefore, I would like to seek for suggestion from the mailing list. Any
comment / suggestion to improve the code is highly welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131223/eca0ad7b/attachment.html>


More information about the Interest mailing list