Android Question Service does not start while the application is open

rscheel

Well-Known Member
Licensed User
Longtime User
As the title says, I have a service that starts automatically from time to time, also starts at the beginning of the application to synchronize data, but there may be a possibility that the service will start automatically while the application is open, such as I can control that.
 

rscheel

Well-Known Member
Licensed User
Longtime User
You can start it from Service_Create of the Starter service.


The starter service starts automatically, there is no need to restart it, it is that the starter service in the past tried to force the application to close, since there never used it again.

I currently have it as follows

B4X:
'Activity Main
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("LayoutMain")
    StopService(Starter)
    StopService(EventosSyncService) 'I stop to do the activity_main first
End Sub

B4X:
'Activity Home
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("LayoutHome")
    If FirstTime Then
        StartService(EventosSyncService) 'Once you have gone to Activity Home, the synchronization started.
    End If
End Sub

B4X:
'Service EventosSyncService
Sub Service_Start (StartingIntent As Intent)
    StartServiceAt("", DateTime.Now + 30 * DateTime.TicksPerMinute, True) 'The service is automatically run every 30 minutes
    If ModConn.s.IsInitialized Then
        Log("La BD Sqlite ya esta inicializada.")
    Else
        ModConn.ConexionSQLite
        ModConn.s.Initialize(ModConn.ruta, "datos_sync.db3", False, ModConn.cc, "")
    End If
End Sub

Instead when starting it in Service_Create would be like this?

B4X:
Sub Service_Create
       StartService(EventosSyncService)
End Sub
 
Upvote 0
Top