Android Question watchdog service and data preserving

sorex

Expert
Licensed User
Longtime User
Hello,

As one of my apps seems to cause issues after running for a while possibly caused by the streaming buffering. The app or entire phone becomes sluggish when that happend and a task kill and restart solves it and it doesn't require a full device restart.

I thought about resetting the services once every few hours.

As I don't want to lose the current active connections so that I can reconnect to them again I thought about...

1. pulling the connections map into the watchdog service
2. let the watchdog service stop the services and restart the services
3. set the connections map back so that it reconnects again (in the watchdog or resetted service)

but this doesn't seem to work as I hoped.

when I log the size of the original service.map and the watchdog.map they are equal before and after stop and start which seems that the stop is something that's running in the background and it's not waited for? The destory hits at a later point according to my logs.

Anyway...

When I check the watchdog.map size in the service_create or service_start it's suddenly 0 again.

Is there straight method that makes me do what I want without the need to save the map to a file and all that?
 

thedesolatesoul

Expert
Licensed User
Longtime User
There are a couple of things/approaches:
1. Figure out what slows down the device/app
2. With services, the Map is stored in process globals. As your watchdog doesnt kill the process, just the service, you dont need to write anything to file.
3. If you kill the process (with ExitApplication), you can write out the file in Service_Destroy and read it in Service_Create.
4. I am not sure what you are storing in the map, but i guess it will setup a new connection anyway.
5. Watchdog.Map being 0 is worrying and worth investigating.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
1. the streaming library I guess, it happend on both the broadcasters and receivers.

3. that's not required, exit application only happends by a long press of an exit button to prevent accidental closes and is only done if nothing works anymore but in these cases it really needs a taskkill.

4. it's just a map with a custom type which holds connections info (ip, socket, streamid etc)

5. yeah, I don't get it either :confused:
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
B4X:
resetting services
receiver connections:1
watchdog connections:1
disconnect all no delete


remove 192.168.50.90
watchdog connections after service stop:1
watchdog connections after service start:1


receiver connections after service start:1
** Service (network) Destroy **
** Service (broadcaster) Destroy **
closing sockets
closing server socket
** Service (receiver) Destroy **
-----------------service destroy-------------
connections:1
** Service (receiver) Create **
server create!!!!!!!!!
recsrv main connections:0
** Service (receiver) Start **
start receiver?
mode:receiver
recsrv start watchdog connections:0
recsrv start rec connection size:0
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
watchdog service has this

B4X:
Sub resetServices
Log("------------------")
Log("resetting services")
recConnections=Receiver.Connections
Log("receiver connections:"&Receiver.Connections.Size)
Log("watchdog connections:"&recConnections.Size)

CallSub2(Receiver,"disconnect","all no delete")

StopService(Network)
StopService(Broadcaster)
StopService(Receiver)

Log("watchdog connections after service stop:"&recConnections.Size)


'Log("starting services")
'Receiver.Connections=recConnections
StartService(Network)
StartService(Broadcaster)
StartService(Receiver)

Log("watchdog connections after service start:"&recConnections.Size)
Log("receiver connections after service start:"&Receiver.Connections.Size)
Receiver.Connections=recConnections
End Sub


and receiver service...

B4X:
Sub Service_Create
Connections.Initialize
Log("server create!!!!!!!!!")
Log("recsrv main connections:"&watchdog.recConnections.Size)
'Connections=watchdog.recConnections
End Sub

Sub Service_Start (StartingIntent As Intent)
Log("start receiver?")
Log("mode:"&Network.MyType)

Log("recsrv start watchdog connections:"&watchdog.recConnections.Size)

timer1.Initialize("reconnect",1000)
timer1.Enabled=True

'Connections=watchdog.recConnections

'Log("main connection size:"&watchdog.recConnections.Size)
Log("recsrv start rec connection size:"&Connections.Size)
 
Upvote 0

Reviewnow

Active Member
Licensed User
Longtime User

in the watchdog service add this at the top
#StartCommandReturnValue: android.app.Service.START_STICKY

Also try to acquire a partial lock
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
ok we sorted it out.

I thought watchdog.map=connections.map would copy the content from one map to the other but it's just a reference to the other map.

So removing the init of the map in the service stopped the clearing the map.

Thanks TDS for the valuable hint! :)
 
Upvote 0
Top