[fpc-pascal] JNI/Android: Java events calling pascal code

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Wed Apr 23 11:31:26 CEST 2014


On Wed, Apr 23, 2014 at 6:10 AM, leledumbo <leledumbo_cool at yahoo.co.id> wrote:
> Hmm...that's beyond my Java skill. Since Felipe who started the topic, you
> can try PM him instead.

So looking at what he originally posted:

setOnCompletionListener(MediaPlayer.OnCompletionListener listener)

And looking into the documentation:

http://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener.html

you need to provide a class which implements the
MediaPlayer.OnCompletionListener interface:

There is nothing in JNI unfortunately which would allow us to create
new classes. JNI is very limited, unlike objc runtime which gives us
access to everything, JNI gives us a limited access to the Java world.

I already asked in the past in Java/Android groups about this, how to
get rid of Java when you need to pass a class which implements and
interface.

The answer is that it is possible: You need to create the class in
...... java bytecode =D And then pass it to Java.

At this point I gave up, considering it too awkward and wrote my
software part in Java and part in Pascal.

Ideally it would not be so hard if we had a bytecode generator which
accepts as input things like classname, which interfaces it will
implement, list of functions and address to their implementation, etc,
etc. But we don't have at the moment AFAIK.

So maybe someone braver will actually do this, since it is possible =D
But I didn't for my Android app in the app store (True Democracy)....

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list