Android Question Service for MQTT server

michw

Member
Licensed User
Longtime User
I have a request that someone suggest or show the part of the code that will allow me to start the connection to the MQTT server and keep it connected.
I want to receive a notification from the MQTT server, that's why I'm doing it for service.
I am more interested in configuring the service module to run non-stop in the background.

THX
Michal
 

michw

Member
Licensed User
Longtime User
Thanks Erel for your links. I'm trying to keep the service working.
I currently have this code:


B4X:
Sub Service_Create
    
    Syntezator.Initialize("TTS")
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
    PWS.PartialLock
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StartForeground(1,n2)
    StartServiceAt(Me, DateTime.Now + 20*1000,True)
    checkConnect
End Sub

the effect is that as the phone's screen is active, the service is called every 20 seconds.
But when the screen is turned off, after some time the service does not work anymore. Only when the phone is unlocked will it start again.
I need the service to work all the time and show me notifications when I receive a message from MQTT.
How can I do this?
 
Upvote 0

michw

Member
Licensed User
Longtime User
ok i change in service_start

B4X:
StartServiceAt(Me, DateTime.Now + 16 * DateTime.TicksPerMinute, True)
    timer1.Initialize("timer1",1000)
    timer1.Enabled=True

and test how long the timer send text to log.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…