Background Process Termination?

I understand that firing off a background process in a data field (I need to do this to grab the Device Sensor's temperature) runs the background process independent of the execution of the actual data field. And even when the data field isn't running (say you remove the data field or switch to another ride profile that doesn't include the data field, or even reboot the device) that background process continues to run. Forever?

I don't know if that is the case in all those situations. But I want to reap/kill my background process as part of my onReset() interrupt when ending an activity.

How? If I'm right and that BG process just keeps running.

Thanks! 

  • A background services runs for at most 30 seconds at a time.  What you want to do is delete the temporal event when your DF ends (onStop is the place, but it may not be called on some devices for a DF.)

    It's actually a bit tricky, as onStop also gets called each time the background service ends, so you want a flag in your AppBase.  Say you have

    var isBackground=false;

    and then in getServiceDelegate, you do

    isBackground=true;

    in onStop, only do the delete if isBackground==true.

  • Thanks! but onStop is wrong I think. You can often hit STOP and then RESUME your activity. Sometimes many times during your ride. I personally don't since I use auto-pause but many do that. So IMHO, onReset is the place to do that... that is when you actually end your activity and hit SAVE... at that point, the ride is over. Agree?

    I see there is an exit and a deleteTemporalEvent. I'll explore these. THANKS Jim!

    exit(backgroundData as Application.PropertyValueType) as Void

    Terminates the current background process.

    All background processes should call this method when they have completed the desired tasks.

  • Yes, as I said, a background runs at most 30 seconds or until Background.exit() is call. In your case, getting the temperature won't even run for a second.

    Seems to me, updating the temperature in a data field as long as that data field is visible makes sense (and is simpler)  if you've not started recording, ended recording, etc.

  • but onStop is wrong I think. You can often hit STOP and then RESUME your activity. Sometimes many times during your ride.

    I think he meant AppBase.onStop(), not DataField.onTimerStop().

  • OH! Got it. Thanks FlowState and Jim. I've never used the AppBase.onStop() before. Just the onTimerStop.