Android Question how to wait for a Service is started ?

Discussion in 'Android Questions' started by peacemaker, Apr 24, 2019.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    HI, All

    I have already debugged app that works with several Cloud services - now 2.
    Each Cloud class module works with corresponding Service module.
    And now i need to add 3rd cloud, GoogleDrive (let's say GD).
    If to try to make the same way structure - i have to start the GD service were the GD class is declared and all needed subs, events are.

    But strange that this 3rd service for GD is starting so slow that i cannot develop in the debug mode.
    In Release the service is started fast and it's OK, but ... i need to debug next functions with GD, but Debug mode is ... a trouble now.

    Any ideas ?
    It seems, i have to wait somehow until the service is started fully...
     
  2. DonManfred

    DonManfred Expert Licensed User

    Raise an event when the service has started.
    Wait for this event in the calling activity.

    Or set a global var (initialized in starter) when the service has started.
     
  3. peacemaker

    peacemaker Well-Known Member Licensed User

    But the StartService is called from a common sub of the code module - how to raise an event ?
     
  4. DonManfred

    DonManfred Expert Licensed User

    the starter service should NEVER be started manually.
    The starter starts before every other activity will start.
     
  5. peacemaker

    peacemaker Well-Known Member Licensed User

    It's not Starter, it's special service for GoogleDrive class work. But one service among 3 clouds is started from a code module sub. This sub is single, common for usage in several points, so ... it's usually placed into a code module, right ?
     
  6. DonManfred

    DonManfred Expert Licensed User

    Again: The starter service IS started before any other service or activity!
    Define global var in the starter and set the value to TRUE if service x has started. GD service for example change Starter.GDrunning to true when started.
     
  7. peacemaker

    peacemaker Well-Known Member Licensed User

    And how to wait for ... this var is changed ?

    Code:
    Do Until Starter.GD_Service_isStarted
            Sleep(
    0)
        
    Loop
    ?
     
  8. DonManfred

    DonManfred Expert Licensed User

    i would try it this way. Anyway i would not use 0 here. Give the system a bit time. try with sleep(250) for ex. It should be "OK"...
     
  9. peacemaker

    peacemaker Well-Known Member Licensed User

    Ohhh... Sleep(x) allows next running, so next subs are called, but no service is started yet.
    It needs to make fully synchronous ...
     
  10. DonManfred

    DonManfred Expert Licensed User

    Surely sleep will return from that sub like you are calling return in this sub.
    Android is event driven. Learn how to work with it.
    Watch the resumeable subs tutorial video.
    Good luck.
     
  11. peacemaker

    peacemaker Well-Known Member Licensed User

    Thanks, but .... the topic question is still open.
    And it seems, the only way is use the Starter service as the common start sub container, with Wait for ...Event from the starting service.
     
  12. José J. Aguilar

    José J. Aguilar Active Member Licensed User

    Not sure, but maybe this thread can help?

    https://www.b4x.com/android/forum/t...rvice-or-activity-and-wait.79856/#post-505701

     
    peacemaker likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice