[Android-development] Getting an Activity instance from C++ code

Mikhail Khvoinitsky mhspacee at gmail.com
Fri Jan 10 07:42:36 CET 2014


Excuse for the late answer.
I've got it to work and I have some notes.
The documentation for QAndroidJniObject is not enough clear:
  * Some methods like QAndroidJniObject::getStaticObjectField are 
templates but it isn't specified in documentation at all. Also, choosing 
the overloaded method depends on template type. Right now the only way 
to learn about it is sources.
  * In the doc of QAndroidJniObject (Detailed Description > JNI Types > 
Object Types) said that the signature of jobject is 
«L<fully-qulified-name>};» but it seems misspelled and should be 
«"L<fully-qulified-name>;"»

On 01/03/2014 10:57 AM, Eskil Abrahamsen Blomfeldt wrote:
> On 01/03/2014 06:37 AM, Mikhail Khvoinitsky wrote:
>> Hello.
>>
>> I am using Qt 5.2.
>> How I can get the Activity instance from C++ code?
>> I have tried this solution http://qt-project.org/forums/viewthread/33771
>> but it isn't working for me (may be it works only in qt 5.1)
>
> Getting it in the way described there should still work in Qt 5.2, but
> it's undocumented and not part of the public API, so anyone using it
> should be clear that behavior could change in future releases.
>
>>
>> Also, I did find something about activity in Qt Android Extras
>> documentation.
>>
>> Note: My Activity is a subclass of Qt's QtActivity.
>
> If your application only has a single activity, set a reference to it in
> the constructor of your Java class, add an accessor for this and call it
> using JNI. Qt Android Extras might help with the JNI part.



More information about the Android-development mailing list