Android Question Advice of How to choose between one service or another

Discussion in 'Android Questions' started by Alberto Michelis, Jun 30, 2015.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Hi, in my app have two services, sometime I need server 1 to be running and som the service 2.

    Im using the following code in a "Code Module", it is ok to do it this way?

    Main.Versionnivel selects the service to run

    Code:
    Sub ChooseReadingService
        
    Log(">>>> choose server version=" &Main.VersionNivel)
        
    If Main.VersionNivel<>0 Then
            
    If ServicioCorriendo<>"PortIt" Then
                ServicioCorriendo=
    "PortIt"
                
    Log("---- tuns on service PortIt ---")
                
    StopService(LeeWebRava)
                
    StopService(LeeWeb)
                
    StartService(LeeWeb)
                
    CallSub(LeeWeb,"Timer1_Tick")
            
    Else
                
    Log("---- still running service PortIt ---")
            
    End If   
        
    Else   
            
    If ServicioCorriendo<>"RavaDelayed" Then
                ServicioCorriendo=
    "RavaDelayed"
                
    Log("---- turns on service Rava ---")
                
    StopService(LeeWeb)
                
    StopService(LeeWebRava)
                
    StartService(LeeWebRava)
                
    CallSub(LeeWebRava,"Timer1_Tick")
            
    Else
                
    Log("---- still running service Rava ---")
            
    End If   
        
    End If   
    End Sub
    Thanks
     
  2. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Any advice?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Use CallSubDelayed instead. Your current code will not work properly. The CallSub will do nothing if the service wasn't running before as StartService doesn't immediately starts the service.
     
    lemonisdead and DonManfred like this.
Loading...