Unusual behavior when modifying properties inside App.onStart() and App.onStop()

I'm seeing weird behavior with the following code (just a modified version of samples/ObjectStore/ObjectStore.mc).

class ObjectStore extends App.AppBase
{
function onStart() {
Sys.println("Enter App.onStart()");

var n = getProperty("xxx");
if (n == null) {
Sys.println("didn't find property, setting to 98");
setProperty("xxx", 98);
}
else {
Sys.println("found property has value " + n);
}

Sys.println("Exit App.onStart()");
}

function onStop() {
Sys.println("Enter App.onStop()");

Sys.println("setting to 99");
setProperty("xxx", 99);

Sys.println("Exit App.onStop()");
}

function getInitialView()
{
return [new View(), new Input()];
}
}


I see the following output when the application starts up and shuts down...

Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Enter App.onStart()
didn't find property, setting to 98
Exit App.onStart()

// terminate app

Enter App.onStop()
setting to 99
Exit App.onStop()
Complete
Enter App.onStop()
setting to 99
Exit App.onStop()


I see this every time that the application runs. There are a few issues with this. First off, the onStop() method is getting called twice. Second, the attempt to overwrite the persistent value while the application is cleaning up fails (the persistent value is not found on every execution of the program. Third, if you comment out the code in onStop(), you'll notice that overwriting the value in onStart() doesn't seem to take effect either.

Travis
  • At this point, my conclusion is that I'm using the persistence system wrong.

    I'm trying to write an app that maintains a collection of data across program invocations. As I've currently written it, the data is deserialized on application startup, the values modified at runtime, and then serialized back out when the application is shutdown. It seems that the persistence system expects me to write the values out every time that they change.

    Is this a bug, or just user error?

    Travis
  • Former Member
    Former Member over 10 years ago
    Doesn't look right does it. The persistent store (in the case of the emulator) is in "C:\Documents and Settings\\Local Settings\Temp\GARMIN\APPS\DATA\App.str" (Win XP).

    Couple of strange behaviors to note:
    1/ If you run with just the onStop code then the setProperty value will be written to the above file apparently before onStop has even been called.
    2/ If you change the setProperty value in onStop it emulator won't notice the change straight away. Some weird semipersistent precaching or something going on me thinks.
  • Former Member
    Former Member over 10 years ago
    One other note. Try your code outside of the onStart & onStop functions and I'm sure it will work, with the exception being that you may still need to quote the integers. See https://forums.garmin.com/showthread.php?146465-Why-can-t-I-run-ObjectStore-sample
  • Travis,

    Is this on Windows? Are you using the command line tools or the Eclipse plug in?

    -Alpha Monkey
  • Yes, Windows. I've tested with both command line and Eclipse builds. I've even gone so far as to build a fresh development environment in a Windows 7 VM, and I am still able to reproduce the problem.