Android Question watchdog service and data preserving

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

  1. sorex

    sorex Expert Licensed 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?
     
  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

    Code:
    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
     
  6. sorex

    sorex Expert Licensed User

    watchdog service has this

    Code:
    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...

    Code:
    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)
     
  7. Reviewnow

    Reviewnow Active Member Licensed User


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

    Also try to acquire a partial lock
     
  8. thedesolatesoul

    thedesolatesoul Expert Licensed User

    When you do:

    Connections=watchdog.recConnections

    and later:
    Connections.Initialize

    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 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! :)
     
    thedesolatesoul likes this.
Loading...
  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