Background widget

Hi,

I have some questions about background processing: I want to design a widget which collects data on a hourly basis. What happens to the background service if the widget is started by user? Will it start another background service which mewns I have to kill the previous?

What happens with the background service if its triggered but currently the widget ie displayed? Will it executed anyway?

  • More println calls to make sure things are happening when you expect (registering for the temporal event, etc.  getServiceDeligate should be called each time the background runs not just once.

  • Hi Jim,

    I traced the problem down, but I have no clue why this happens:

    1. If I code this:  Background.registerForTemporalEvent(new Time.Duration(300));

    thinkgs were fine. Everything is as expected.

    2. If I code this:

    var nag = Application.getApp().getProperty("naggingFrequency");
    Background.registerForTemporalEvent(new Time.Duration(nag));

    the background process is initialiazied but the onTemporalEvent function is never called on an temporal event. Even if I cast nag with toNumber(). BTW, nag is configured to be 3600.

    Do you have any hints?

  • make sure that "nag" is a number. See the new developer FAQ for a long time issue with numbers in settings.

  • Hi again,

    I made a new project and setup only background, nothing else. But with this new project, background doesn't work either. If I send a temporal event, nothing happens in the service. Here is the project. 

    www.dropbox.com/.../Weekly Steps Goal.zip

  • Runs fine for me.

    Here's the log of just letting it run and the background runs every 5 minutes:

    Background: getServiceDelegate() is called
    Background: init background process
    Background: 79200
    Background: 28800
    Background: 49647
    getInitialView() of main app is called
    BG registered
    Background: getServiceDelegate() is called
    Background: init background process
    Background: 79200
    Background: 28800
    Background: 49647
    Background: on Temp Event
    onBackgroundData called
    Background: getServiceDelegate() is called
    Background: init background process
    Background: 79200
    Background: 28800
    Background: 49947
    Background: on Temp Event
    onBackgroundData called
    Background: getServiceDelegate() is called
    Background: init background process
    Background: 79200
    Background: 28800
    Background: 50247
    Background: on Temp Event
    onBackgroundData called
    

    And it does if I do a temporal event in the sim.

  • Hm, then something is going on with my environment. I am using backgrounding in another widget and there it works like you describe. But with this, I posted here, the simulator doesn't select it by default in the temporal event drop down box. Can I reset the environment somehow? 

  • You don't need to select it in the popup.  Just fire a temporal event while it's running.  Are you seeing the scheduled ones run?

  • You're using a unique manifest ID for your widget, correct?  If the sim has two apps with different names but the same ID, things  can get confused.  To play it safe, in the sim, do File>Delete All Apps

  • Your last hint worked. Thank you, Jim. I dont know what I did but now I can see the temoral event immediatley

  • When you build an app, it's in the project bin folder, but also gets copied to the sim's temp director.  If you chage the name of an app, you can wind up with two prg files with different names but the same manifest ID in the sim's temp directory, and that can cause issues.  So if you change the name, always do the "delete apps" in the sim to clear them out of the sim's temp directory.