Hello there,
I'm making a DataField app and I need to fetch json data but it says that I can't use Toybox.Communications whith datafield
Does someone have an idea?
Thanks in advance
Hello there,
I'm making a DataField app and I need to fetch json data but it says that I can't use Toybox.Communications whith datafield
Does someone have an idea?
Thanks in advance
You can do comm in a DF, but only in a background process. For example, I have a DF that has a background that runs every 15 minutes that gets weather data and displays it.
Thanks jim for your reply I’m new to monkey can you link an example if possible
Here's a while thread about backgrounding. The same principles apply to a DF.
Thanks again Jim for your help I'll try that
OK, I've succeeded in retrieving data from Json but it seems that the background routine is fetched often with a high latency (I've only a simulator from now) , can I force background function to be run immediately after app starts?
The most often you can run a temporal event is every 5 minutes. When you register an event the very first time, it will run right away,
In a DF, you really don't want it to run every 5 minutes unless the DF is in use, so what you want to do is delete the temporal event when the DF exits, and if you run it again (more than 5 minutes later) the background will run right away.
But this gets a bit tricky, as you can't just always do the delete in onStop(), as that runs for both the background process and main process.
Some things in your AppBase run for both the main process and background (like onStop()), and some are unique to either the background or main process.
Another thing to note is that the foreground and background variable are separate.. So what you want to do is in something like getServiceDelegate() (it's only run in the background), is to set a variable (the background's version of that variable to be exact), and then check that in onStop() to see if it's the man app before you do a delete.
so... like this:
class MyApp extends Application.AppBase { var inBackground=false; (other stuff) function getServiceDelegate(){ inBackground=true; return [new MyServiceDelegate()]; } function onStop(state) { if(!inBackground) { Background.deleteTemporalEvent(); } } }
I don't know why while it should work it seems not to solve the problem.
The temporary workaround is to delete temp files
I'll dig it