getServiceDelegate () error in WF/BG

Hi,

sometimes, i have an error on account of the init of my WF

getServiceDelegate is called before any app init:

it gives me this on console(just after running my WF) :


Error: Unhandled Exception
Exception: UnexpectedTypeException: Expected Object/Array/Dictionary/ByteArray, given null
Stack:
  - launchStockRequest() at E:\...\WebRequest.mc:64 0x100009f2
  - initialize() at E:\...WebRequest.mc:352 0x10001ad7
  - getServiceDelegate() at E:\...CubeWatchApp.mc:182 0x100007f6

****getInitialView =****
 in userSettings :
***enter  onShow..
*** exit onShow..
Background: ****background Init ****true
Background: **** initialize**** TOTAL MEM28688
Background: **** initialize**** USED MEM21592
Background: **** initialize**** FREE MEM7096

Probably logical to have an error if no init is made, but how can this happen, and how can i avoid this pb?

May it be some BG process still running in mem ?

Thanks

Marco

  • getServiceDelegate is called by the background when the background starts.

    That can include when the background doesn't run due to a temporal event, and two cases are when an app is first installed or updated - onAppInstall() and onAppUpdate() would also be called, and that sounds like what you are seeing.

    Sounds like you might be doing things in initialize() that you should be doing in onTemperoalEvent()

  • Thanks.

    Probably something like onAppInstall, since i just deleted all apps in simu and restarting my app.

    But i have nothing in :

        function onAppInstall() {

    //        Sys.println("onAppUpdate");
    //        App.onAppInstall();
        }

        function onAppUpdate() {
    //        Sys.println("onAppUpdate");
    //        App.onAppInstall();
        }

    and in initialize() :    }

        function initialize() {
            AppBase.initialize();
        }

  • what do you have in getServiceDelegate()?

  • this :

        function getServiceDelegate(){
            return [new WebRequestServiceDelegate()];
        }

  • so where is launchStockRequest() being called from?

  • laucnhStockRequest is called from within WebRequestServiceDelegate,

    in makeWebRequest, to test if makets are closed or not (to avoid a request for nothing) for this particular stock (can be on Nasdaq/EUR or anywhere..)

  • it should be a little memory bug in the simu,as it crashes sometimes (java error, freeze, no sync with App Settings Editor, etc).

    This error does not have stop the WF, running, so BG just send some error msg .

    Thanks for your help Jim.

    I now have some work on onShow which seems not to recover my OS (hum, maybe not the fault of onShow!) and with Lat/long that i lost even in OS. (proably i have some job to do with OS !)

  • Last question of the day :

    i had an error, due to the called server.

    I made as usual my request, Json format waiting, is ok 99%.

    but In the console i saw this :

    Error: Unexpected Type Error
    Details: failed inside handle_json_callback
    Stack:

    in HTTP Traffic Stats :

    HTTP/1.1 503 Service Unavailable\r\n
    Connection: keep-alive\r\n
    Server: Cowboy\r\n
    Date: Thu, 05 Dec 2019 20:21:11 GMT\r\n
    Content-Length: 506\r\n
    Content-Type: text/html; charset=utf-8\r\n
    Cache-Control: no-cache, no-store\r\n
    \r\n
    <!DOCTYPE html>\n\t<html>\n\t  <head>\n\t\t<meta name="viewport" content="width=device-width, initial-scale=1">\n\t\t<meta charset="utf-8">\n\t\t<title>Application Error</title>\n\t\t<style media="screen">\n\t\t  html,body,iframe {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t  }\n\t\t  html,body {\n\t\t\theight: 100%;\n\t\t\toverflow: hidden;\n\t\t  }\n\t\t  iframe {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t\tborder: 0;\n\t\t  }\n\t\t</style>\n\t  </head>\n\t  <body>\n\t\t<iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe>\n\t  </body>\n\t</html>

    Any way to provide and "catch" this system error (i manage error codes in onBGdata...) ?

    Thanks !

  • but from what function in WebRequestServiceDelegate?

  • function makeRequestFirstStock :

    if (launchStockRequest(tStockOne) ) { Comm.makeWebRequest(w3Api, params, options, responseCallback);    }

    sorry, i answered "in makeWebRequest" it was a too quick answer.

    But i have to change my all BG, to reduce memory usage/ BLE usage / battery usage

    Now i manage (at leat enough to get my data!) BG, i understand all you adviced me and the threads about this point.