background app wakeup without prompt

Hi,

Just been looking at background process functions to see if I can wake my app at a certain time each day. The only call that can switch to the app gives a prompt that must be responded to so requires user intervention. I don't want this as the app would take a measurement whilst the user was asleep.

Is there anyway of doing this?

I also have the issue that the App.Appbase class can't use Ui calls when in background but all the functions (onStop, initialView etc) by definition are defined in background. Also you can't have code in onStart() for use in foreground when it's called as background as these seem to error with undefined symbols. It would help if we can use an attribute to have different onStart() for foreground and background use!

Thoughts welcome.

Regards,

David

  • With a background service, you can check the time vs sleep/wake times and not do anything during that time.

    Some functions in AppBase are called for both the main app and background service (initialize(), onStart(), onStop() for instance)  Some are called only for the main app (getInitialView() and onBackgroundData for example), and then, things like OnAppInstall(),onAppUpdate() and getServiceDelegate() only in the background.  Your UI calls should be in the view and not AppBase for about everything, though it's common to call WatchUi.requestUpdate() cor things like onSettingsChanged() or onBackgroundData().

  • Hi Jim,

    Thanks for coming back. I use onStart() to setup all my buffers and global variables, sensors etc before loading the initial view which controls sequencing etc. OnStop() then saves a whole bunch of information for the next run, again based on the globals. I guess I could fake an initial view that setup everything then switched to the current top level view or add a fair chunk of code to that initial view but would lose some of the stop functionality.

    I see what you are saying about doing a time test in the background but this would only allow me to pass back a flag saying now would be a timed driven run when the user next runs the app. The other choice is to use 

    Background.requestApplicationWake

    which asks the user whether they want it to run.

    What I need is a forced run of the app from the background with no user intervention. Unless of course the background.exit()
    always then does a foreground call to the app and I've misunderstood.
    Regards,
    David
  • You don't need to use requestApplicanWake().  The background will run and return data by way of Background.exit(), which will be seen the next time the main app runs.. In the background service, you can use getBackgrounddata() and pass data from multiple times the background runs if the main app hasn't run yet.  I have one app where the background can run over 100 times and provide data fron each time it ran to the main app if the main app hasn't run.

    Unless you provide a gate (by way of a variable). onStop runs each time the background runs. no only when the main app runs.

  • Hi Jim,

    I think I understand this but my current understanding is that there is no mechanism to autonomously wakeup and run an app (it would not need UI interaction those these could be displayed) based off a timer. All that the backgrounding does is to run a helper process for the main app which uses its results as and when the user starts the app.

    Is there anyway to do what I want?

    thanks,

    David 

  • I'm not sure what it is you want to do.

    There is no way to run your main app without user interaction of some sort, be it manually starting it or by way of a requestApplicationWakeup.  Having it just start on it's own probably wouldn't be that friendly as the user could be doing something else.

    What you can do, is have the background run say every hour and get the data you want, and then the next time the main app runs, display that data.  And by using getBackgroundData in the background service, return X hours worth of data the next time the main app runs.  I do that with a battery monitor that reads the battery level every  X minutes, and when the main app runs, it can see all the samples since it was last run (up to 144 samples).  Each has a timestamp, so I can do a graph of the data and note any gaps (background services don't run if a different CIQ device app is running..)

  • Thanks. The ask I am getting is for the app to wake at say midnight do a test and then save the results. Obviously the user will (hopefully) be asleep hence the need for no interaction. The processing code is considerably more than 28kB with its buffers, access to HR interval data, FIT data writing, stats generation, storage and properties access etc.

    I could develop a new app and cut out a lot of the functionality of the UI then reappraise the memory model and signal processing but then this app and the current one would not be able to merge data.

    Sounds like the way I would need to go. Can a background access interval data from the optical sensor or a connected strap?

    Thanks,

    David

  • You can't do activity recording in a background service.  The service only runs for at most 30 seconds.

  • Ok. Thanks for the guidance Jim. I can't do what I intended. The background would need to run for 5 minutes or more

  • 30 second max.  Then it's killed by the system.