Hi, I met another problem just now.
My code is below.
---------------------app----------------------
using Toybox.Application;
using Toybox.WatchUi;
//golbal variable
class MyApp extends Application.AppBase {
var myModel;
var myDelegate;
function initialize() {
AppBase.initialize();
myModel = new $.MyModel();
myDelegate = new $.MyDelegate();
}
// onStart() is called on application start up
function onStart(state) {
}
// onStop() is called when your application is exiting
function onStop(state) {
}
// Return the initial view of your application here
function getInitialView() {
return [ new MyView(), myDelegate ];
}
}
---------------------model----------------------
class MyModel {
// Constructor
function initialize() {
System.print("Model's constructor invoked");
// initialize FIR filter
var options = {:coefficients => [ -0.0278f, 0.9444f, -0.0278f ], :gain => 0.001f};
try {
mFilter = new Math.FirFilter(options);
mLogger = new SensorLogging.SensorLogger({:enableAccelerometer => true});
mSession = ActivityRecording.createSession({:name=>"Sport", :sport=>ActivityRecording.SPORT_GENERIC, :sensorLogger => mLogger});
}catch(e) {
System.println(e.getErrorMessage());
}
.......
}
---------------------delegate----------------------
class MyDelegate extends WatchUi.BehaviorDelegate {
var myModel;
function initialize() {
BehaviorDelegate.initialize();
myModel=Application.getApp().myModel;
}
........
}
---------------------delegate----------------------
class MyView extends WatchUi.View {
function initialize() {
View.initialize();
}
........
}
Output is:
Background: Model's constructor invoked
Error: System Error
Details: Cannot create a new session while recording is active
Stack:
- initialize() at **/MyModel.mc:52 0x10001d84
- initialize() at **/MyApp.mc:10 0x10001998
Model's constructor invoked
Obviously, the constructor is invoked twice, so weird????
Thanks a lot for any help.