Android Question Service - What happens if started again?

Discussion in 'Android Questions' started by FrankBerra, May 22, 2015.

  1. FrankBerra

    FrankBerra Active Member Licensed User


    I developed an app that has a service running aturomatically (StarServiceAt) in background at specified intervals. The service can also be started manually (by pressing a button) and it takes about 15 seconds to complete the whole computation.
    Everything is going fine but i must foresee all possible scenarios.

    My question is:
    If the service is already started and it is in the middle of its computations, what happens if i start again manually the service?
    In this case the routines in the previous service-runtime are interrupted or service continue to run until the end?
    If in the service i write files with discrete amount of data, starting manually the service in the middle of this operations can break up the saved data?
  2. Erel

    Erel Administrator Staff Member Licensed User

    1. Remember that the service code is executed on the main thread.
    2. Service_Start will be raised whenever the service is started. Service_Create will be raised once (unless you destroy the service).

    As the code is executed on the main thread, it will not be interrupted. The same is true about the file writing.