I tried to extend a class/interface from "Androidapi.JNI.App.pas" (TJservice), I need to extend this class for make a service. Is it possible? How?
some example of java/android service
I need to override method like : oncreate, onbind, ondestroy. But I don't know how.
I tried something like this:
type Tandroidservice= class(TJService)
function onBind(intent: JIntent): JIBinder; override;
procedure onCreate; override;
procedure onDestroy; override;
procedure onStart(intent: JIntent; startId: Integer); override;
end;
with this error:
[DCC Error] Unit1.pas(13): E2137 Method 'onBind' not found in base class
[DCC Error] Unit1.pas(14): E2137 Method 'onCreate' not found in base class
[DCC Error] Unit1.pas(15): E2137 Method 'onDestroy' not found in base class
[DCC Error] Unit1.pas(16): E2137 Method 'onStart' not found in base class
[DCC Error] Unit1.pas(13): E2065 Unsatisfied forward or external declaration: 'Tandroidservice.onBind'
[DCC Error] Unit1.pas(14): E2065 Unsatisfied forward or external declaration: 'Tandroidservice.onCreate'
[DCC Error] Unit1.pas(15): E2065 Unsatisfied forward or external declaration: 'Tandroidservice.onDestroy'
[DCC Error] Unit1.pas(16): E2065 Unsatisfied forward or external declaration: 'Tandroidservice.onStart'
Your only current option is to inherit from a Java class and then use JNI to call into Delphi and do a thread switch to the FMX thread.
My CodeRage 8 session (next week as of time of writing) shows how to do this with an activity. It's much the same process.
That won't help you now, other than to know you can't inherit directly in Delphi from a Java class in Delphi for Android, although in Delphi for iOS you can inherit from an Objective-C class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With