Android Question watchdog service and data preserving

Discussion in 'Android Questions' started by sorex, Mar 13, 2015.

  1. sorex

    sorex Expert Licensed User


    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 and the 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.


    When I check the 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?
  2. thedesolatesoul

    thedesolatesoul Expert Licensed 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.
  3. sorex

    sorex Expert Licensed 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:
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Code? Nested structures cause issues in writing out to files, many times they are flattened to strings.
  5. sorex

    sorex Expert Licensed User

    resetting services
    receiver connections:
    watchdog connections:
    disconnect all no delete

    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
    server socket
    Service (receiver) Destroy **
    service destroy-------------
    Service (receiver) Create **
    server create!!!!!!!!!
    recsrv main connections:
    Service (receiver) Start **
    start receiver?
    recsrv start watchdog connections:
    recsrv start rec connection size:
  6. sorex

    sorex Expert Licensed User

    watchdog service has this

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

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


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

    'Log("starting services")

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

    and receiver service...

    Sub Service_Create
    Log("server create!!!!!!!!!")
    Log("recsrv main connections:"&watchdog.recConnections.Size)
    End Sub

    Sub Service_Start (StartingIntent As Intent)
    Log("start receiver?")

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



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

    Reviewnow Active Member Licensed User

    in the watchdog service add this at the top

    Also try to acquire a partial lock
  8. thedesolatesoul

    thedesolatesoul Expert Licensed User

    When you do:


    and later:

    you are clearing wathdog.recConnections as well.

    That is why you get an empty map.
    Jmu5667, Reviewnow and sorex like this.
  9. sorex

    sorex Expert Licensed User

    so it is a reference and not pumping the data into that other map?
  10. sorex

    sorex Expert Licensed User

    ok we sorted it out.

    I thought 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! :)
    thedesolatesoul likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice