Jump to content
TurboMagic

Using a timer in an Android SharedObject

Recommended Posts

Hello,

 

this question is quite low level. For the purpose of being used from some completely different programming language on Android I'm trying
to check if I can rework a Windows DLL of mine into a shared object.

 

I can create a shared object (.so) already, for this one has to be aware that the library project type in Delphi which would create a DLL on
Windows won't create a .SO on Android. I consider this a bug or at least a missing feature. But you can create a .SO by creating an FMX
project and throw out the use of the default generated form (and everything in the begin / end block of the DPR).

The resulting SO can be used if the functions/procedures are called dynamically.

 

Next step would be to get a timer up and running.

I tried the FMX time, but that didn't work, it crashes as soon as I want to create it (segfault 11).

So I looked into how this one is implemented and copied that code into my application (to have as few connections with RTL and
FMX as possible). But it crashes on creation as well.

 

I looked what is done under the hood and it is this:
The timer needs a JHandler and this shall be fetched via Androidapi.Helpers.TAndroidHelper, which has a MainHandler class property.
This accesses a FMainHandler field and if that is nil, it is initialized, but that needs a TJLooper.

As far as I understood (see https://developer.android.com/reference/android/os/Handler) this is the equivalent of the Windows message loop.

 

Can I replicate that somehow in my SO? What would I have to do to get this working?
My test project is attached. If you want to try it, compile the libSOTest.so first, then run libSOTestGUI.

 

Best regards

 

TurboMagic

SOTest.zip

Share this post


Link to post

Thanks for these links. The first one I know and already tried, but it crashes as well, but I need to try to understand their soruce better.
I had thought to give TTimer a 2nd try as that one might be easier to understand. The 2nd link is really new to me.

Share this post


Link to post

While Marco's blog post is nicely written it's not excactly what I'd need. Threading is not really new to me,
but I would have the need to wait in there or so. But the Kastri Timer is something I really should look at. Thanks
for bringing that one up!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×