Jump to content
Sign in to follow this  
limelect

Android Service

Recommended Posts

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
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 by Rollo62
  • Like 1

Share this post


Link to post

@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

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

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

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 by Rollo62

Share this post


Link to post

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

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

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

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

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
Sign in to follow this  

×