Android Question CallSub when Activity Paused

imgsimonebiliato

Well-Known Member
Licensed User
Longtime 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
Longtime User
I know the usage of CallSubDelayed, but I don't want that the request is sending to waiting queue.
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0

imgsimonebiliato

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

thedesolatesoul

Expert
Licensed User
Longtime User
It isn't necessary to display the activity, but only execute the sub
Yes. The activity sub does not exist without the activity.

If the sub is written in a way that it can be executed without needing the activity then it should be in a code module or a service.
 
Upvote 0

imgsimonebiliato

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

imgsimonebiliato

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

imgsimonebiliato

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

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

imgsimonebiliato

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