How to do it...

The Android Delphi compiler allows you to declare a specific class as a Generic Java Import of an SDK Java class. The class that does this magic is declared within the Androidapi.JNIBridge.pas unit, and is declared as follows:

TJavaGenericImport<C: IJavaClass; T: IJavaInstance>

The TJavaGenericImport is a generic class that we can use to make the declaration of imported Java object factories easier. Using this class, we split the class methods and instance methods into two interfaces. This class blends the two interfaces into one factory that can produce instances of Java objects, or provide a reference to an instance representing the Java class. Moreover, Android Java SDK uses Java String objects, while Delphi uses strings. ...

Get Delphi Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.