Weird behavior using setProperty()

Former Member
Former Member
So I'm experiencing some weird behavior in my app. Basically, I have 7 arrays stored in object storage for heartNums, which is an array of size 48, containing strings in the format "(heartTotal,heartCount,heartAvg)", for each 30-minute interval in the day, a total of 48. 7 arrays for 7 days worth of storage. Now, what's happening is whenever I test it on the simulator, it properly sets day1's array in the object storage after gathering some data(which checks every minute), as seen when I send it to a companion mobile app to be printed(the Comm sample that's given). That is, day1 now has one array that has some information in it, and day2-7 still have "(0,0,0)"'s for all indexes(as does day1 for any time intervals that haven't been recorded). Now, the weird part is when I build the very same app onto my VAHR, after it gathers some data, and then send it over to the mobile app to be printed, it shows the correct numbers for day1, however day2-7 also have the same data for day1, rather than 0s.

I've got no idea as to why this is happening on my VAHR and not on the simulator, so I'm kind of lost on how to solve it, exactly, so any help is appreciated.
  • Are you using the Object Store (the .str) or the Settings file (the .set) for this?

    The difference is if you use <property id= If you do, it's the .set
  • Former Member
    Former Member over 8 years ago
    They're string arrays...though now I'm just even more confused, I commented out all the setProperty()'s for day1->day 7...saved it, built it again onto the watch and it's still saving it to day1->7 and printing the same numbers, so I'm thinking maybe it's just a problem with how eclipse is building it? I really don't know.
  • I changed my last post, but a note... Even if you commented out the setProperty() calls, did you also delete the .str (or maybe .set, see my changed post) file for your app? If you saved it once, it stays there unless you over write it or delete the file(s)
  • Former Member
    Former Member over 8 years ago
    So...now I feel really stupid. I should have been keeping out for this programming mainly in Java, and I guess I probably missed it in the documentation somewhere but it seems like it's all pointers. I was initializing the day1-7 arrays with the same empty array, so I guess it's essentially a pointer, as when I called .getProperty on one array, it called the same array that was initialized for all the other days, and changed the values for those as well. I initialized all of them separately and now all the other arrays are empty even when I update one. Also, I guess it really is pointers as that was why it was still updating even when I commented out the setProperty()'s, because I was directly changing the variable I got from using getProperty(), and then setting it after, even though it was already changed. At any rate, it seems to be solved now.
  • One thing that's useful with sideloads on a device is "Sys.println()" In the sim, you see those in the console, and on a real device you can see them too. And there are times where things might not be exactly the same in the sim and on a real device, when it comes to simulated data vs real data, etc.

    If your app is <myapp>.prg, in the logs directory on the device, you can create <myapp>.txt and see that output too! (it must be pre created)
  • I have 7 arrays stored in object storage for heartNums, which is an array of size 48, containing strings...

    So you have a minimum of 55 arrays and 336 strings for a total of 391 objects allocated by the application. I don't recall what the object limit is, but I believe it is 512. You may run into exceptions if you go over the limit. Additionally, there is an 8K limit on the size of the object store. Given that you have at least 336 strings in the object store, you should be able to about strings that average about 24 characters in length before hitting this limit. Just something to keep in mind...

    Back to your question...

    day1 now has one array that has some information in it, and day2-7 still have "(0,0,0)"'s for all indexes(as does day1 for any time intervals that haven't been recorded).

    Makes sense.

    Now, the weird part is when I build the very same app onto my VAHR, after it gathers some data, and then send it over to the mobile app to be printed, it shows the correct numbers for day1, however day2-7 also have the same data for day1, rather than 0s.

    It sounds like your days arrays are improperly shared somehow, or there is a problem sending the write data to your companion app.

    If you can, it might be helpful if you could post the code for how you allocate these arrays and associate them with the object store. It might also help to add some instrumentation to show the data that you are transmitting to the mobile app before you actually send it.

    Travis