Android Question CallSub when Activity Paused

imgsimonebiliato

Well-Known Member
Licensed User
Hello,
I use a service to do a request http to a web server.
I need to execute this request, even when the user exit from the app.

How can I do?
 

imgsimonebiliato

Well-Known Member
Licensed User
I know the usage of CallSubDelayed, but I don't want that the request is sending to waiting queue.
 

imgsimonebiliato

Well-Known Member
Licensed User
Hello @thedesolatesoul,
from the log, I've got:

B4X:
** Service (screalist) Create **
** Service (screalist) Start **
1
2
** Activity (main) Pause, UserClosed = false **
3
4
5
sending message to waiting queue (CallSubDelayed - CreateLists)
But the sub "CreateLists" it isn't execute on the background
 

imgsimonebiliato

Well-Known Member
Licensed User
Yes..
Here it is the code of the service module:


B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
Dim Time As Timer
Dim Counter As Int
Counter = 0
End Sub

Sub Service_Create
Log("--Service Started--")
Time.Initialize ( "Time", 1000 )
Time.Enabled = True
End Sub

Sub Time_Tick
Counter = Counter + 1
Log(Counter)

If Counter = 5 Then
    CallSubDelayed(Main, "CreateLists")
    Counter = 0
End If
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy
Time.Enabled = False
End Sub
 

imgsimonebiliato

Well-Known Member
Licensed User
It isn't necessary to display the activity, but only execute the sub
 

imgsimonebiliato

Well-Known Member
Licensed User
And if it is written in a way that it can't be executed without needing the activity?
 

imgsimonebiliato

Well-Known Member
Licensed User
Ok I understand.
And, if I want that this service continues his life cycle, even when the user kills it?
 

imgsimonebiliato

Well-Known Member
Licensed User
Please, can you post some example code for a foreground service?
 

imgsimonebiliato

Well-Known Member
Licensed User
Is it possibile, to start the service, when the user power on the device?
 
Top