My service is working fine, stating it as TJService.JavaClass.START_STICKY but if I close host it remains running on the Android memory, but will act no more. The main loop if locked on a Thread (Also tried a TTask). Android keep it as Idle forever.

Comments

  1. Please provide your code for onCreate event of your service

    ReplyDelete
  2. Tomasz Andrzejewski here you are:
    Th := TThread.CreateAnonymousThread(
    procedure
    begin
    while True do
    begin
    ProcessSomeData();
    ReadSomeData();
    Sleep(1000);
    end;
    end);

    FSupportThread.Add(Th);

    Th.Start;

    That FSupportThread is a TObjectList that I tried to keep in memory after the Host closes. The bad here is that calling a stopService() method (JNI) locks the host.

    ReplyDelete
  3. Do you really need reference to created thread ? Please remove it and just create anonymous thread (with start). I have this same scenario (without reference to created thread) and everything works ok. If you need some kind of persistence try to use database.

    ReplyDelete
  4. Tomasz Andrzejewski When you close your host, the service remains working? I put a TNotification about 30s but when I close the host the service stop to work, but it remains in memory in Idle state.

    ReplyDelete
  5. If main host (in android starting intent) has gone out from the scope your service is recreated. In my scenario also. I have service that's pinging my rest service each 39 seconds. After close of main application service is recreated and than starting job (I have notification when service starts)

    ReplyDelete

Post a Comment