hi friends,
when i have pause (speed =0) i put session.stop in this way.
function update(dc) {
if( ( session != null ) && session.isRecording() && (activityInfoX.currentSpeed == 0) ) {
session.stop();
}
else {
session.start();
}
}
but i receive error message that session.start() not works on update(dc) function.
how i can do ?
thanks
What's the error message say?
But, I also wouldn't do this in onUpdate(). Consider the following.
User is running your app and gets a notification, stops to look at it/deal with it. During that time, your onUpdate() doesn't run. Same if the user opens the music player, stops to pick a playlist. Same thing. You're onUpdate() doesn't run. It would be best to do this in a timer.
Also, speed=0 isn't a sure thing, as with GPS, there's a bit of a "wobble" where that may indicate you're moving a bit when you're standing still. Try starting a GPS activity and just put the watch on a table, and you'll see things like distance climbing.
Error: Unexpected Type Error
Details: Failed invoking <symbol>
Stack:
- onUpdate() at C:\Users\scdstf\eclipse-workspace4\GpsBike51_autostop2\source\InputView.mc:290 0x10001904 Unexpected Type Error
in onUpdate (C:\Users\scdstf\eclipse-workspace4\GpsBike51_autostop2\source\InputView.mc:290)
You probably don't want to mess with turning sensors or GPS on/off. Consider GPS, when you turn it back on, it could take a bit of time before it gets a new fix. And the Tempe can take about a minute to reconnect.
ONE_SHOT really isn't an option. What can happen is you can get a "Last_known" location accuracy, when you really want GPS fired up.
In your code you will repeated call start() each time onUpdate() is called unless the speed is 0. It could just be things go haywire when that many starts are called when the session is already started.
Yes Jim. My code not works now.
I must evaluate fine where i can put re-start session.
thanks
if you want to avoid repeatedly calling start() or stop when you don't need to, you could just use a boolean
var pause=false;
...
if(.. && !paused) {
paused=true;
//do stop()
} else if(.. && paused) {
pause=false;
//do start();
}
function update(dc) {
if( ( session != null ) && session.isRecording() && (activityInfoX.currentSpeed == 0) ) {
session.stop();
}
else {
session.start();}
}
If session == null, you call session.start(), which results in an unexpected type error (the null object has no methods).
That said, I'm with @jim_m_58. You should consider doing this outside of your draw code. You should use a timer or the sensor callback for stuff like this.