limelect 48 Posted June 15, 2021 I need an Android service that stays on even if the application is closed. With the service, I want a timer that fires a message every few seconds. The main form will (maybe?) communicate with the service. I looked at http://cc.embarcadero.com/item/30439 or delphi.org/2015/09/minimalistic-android-service-with-delphi-10-seattle/ and theory and a few more sources none gave me my need. On the minimalistic ServiceUnit, I tried to use it by putting a timer in it seems it does not use it. putting a breakpoint did not stop. It seems I do not understand how the ServiceUnit is used P.S I use the emulator and there I can see in the running service "radhost" I am using D10.2.3 Thank you for your help AndroidSimpleService.zip ServiceUnit.pas Share this post Link to post
Rollo62 536 Posted June 15, 2021 (edited) 15 minutes ago, limelect said: by putting a timer Usual timer do not work in mobile services. For such hardware related system, I would also consider to use a real device, forget the emulator. Only real hardware will show you real problems with the app. Try to use the latest Delphi version, 10.2.3 is already centuries behind, and its already tough to get 10.3.3 running with current devices. Edited June 15, 2021 by Rollo62 1 Share this post Link to post
limelect 48 Posted June 15, 2021 @Rollo62 Thanks but 1. well putting a BreakPoint did not break in ServiceUnit which means the program does not use the ServiceUnit. 2. 10.3 or 10.4 has nothing to do with my problem 3. emulator should be ok too. Share this post Link to post
Rollo62 536 Posted June 15, 2021 Mobile platforms behave pretty much different, try logging instead of debugging. Debugging in a service, not sure if this is working at all. FMX behaves not as easy as VCL was (which is not caused by FMX, but by the platforms most of the time ). Share this post Link to post
limelect 48 Posted June 16, 2021 Ok I understand.But lets tackel it diffrently. To see if "ServiceUnit" works how do I send/trigger the main form from the service? How do I send a string or what ever to the main form? Share this post Link to post
Rollo62 536 Posted June 16, 2021 (edited) Services react usually on some system events, like notification, to run services in the background with heavy tasks in mobile is highly restricted and not really wanted by the OS manufacturer. https://developer.android.com/guide/components/services https://developer.android.com/reference/android/app/Service#ProcessLifecycle I really would recommend not to start with a service as first project, to get a better idea about what is possible in mobile, and whats not. To have a stable main app should be your first goal. Mainly these are no theoretical technical issues, but permission issues. The phones are really very sensitive and killing your app without any warning, if something goes against their everchanging rules, which make it hard to debug. Timers can be possible, but they are not the normal timers as we know it. https://github.com/grijjy/DelphiPlatformTimerQueue You better explain what you really want to do with it. Edited June 16, 2021 by Rollo62 Share this post Link to post
limelect 48 Posted June 16, 2021 Ok. I want to create tasks in DB as of time. When the time comes a popup will tell me of the task to do. Thats it very simple. Since the form will not be open all the time I thought of service. Share this post Link to post
Rollo62 536 Posted June 16, 2021 How long are those tasks ? This can be probably be done by threads in the background, when app goes to Background the OS gives usually some time to finish everything, I'm not sure but I think that works up to 10 min. without big problem (if not the new OS versions have reduced that). Just a few operations should be OK, if its not too timeconsuming. Share this post Link to post
limelect 48 Posted June 16, 2021 Things can be even days. Why? as a humen being i touht of things to do and later forget. I want something to remind me. Share this post Link to post
limelect 48 Posted June 16, 2021 well it is not my need. I want a timer (check time.Task) even if the form is closed. Share this post Link to post