Access the AppFramework from a background thread

2259
3
03-29-2016 06:45 AM
KenGorton
Esri Contributor

I would like to leverage components of the AppFramework while my app is backgrounded on the device. Is the AppFramework (or other Qt lbraries such as QtPositioning) available to the javascript file that provides the background functions to the WorkerScript element in the UI thread? Our own doc says, "On mobile devices where you have limited resources and variable network speed it is advisable to perform long running tasks on a background thread." (Performance considerations—ArcGIS Runtime SDK for Qt | ArcGIS for Developers ) so it would seem this is possible, but how is this accomplished? The same import statements used in the qml file don't work in the js file. Any help is appreciated and actual examples will be warmly welcomed.

Thanks.

0 Kudos
3 Replies
LucasDanzinger
Esri Frequent Contributor

Thanks Ken. We should probably fix up that doc a bit for QML. The ArcGIS Runtime QML API handles all of the threading for you, so you shouldn't need to worry about moving long running tasks onto another thread. If you are finding performance issues or limitations with our API, then I would suggest logging a bug for that so we can take a look at it. As far as Workerscript, I have tried getting this to work in the past, but it seems that this QML type is limited. If you notice in the doc (http://doc.qt.io/qt-5/qml-workerscript.html), it says you can only pass in certain types to the sendMessage() method, and explicitly states that QObject* types cannot be passed over. Most all of our API types derive from this, so it is a limitation of Workerscript. Like I said, if you find that a task is not performing well in the API, then this could potentially be a bug we need to address. In addition, our Quartz release will be returning many more Model types, that will allow you to directly plug results into views, thus eliminating the need to do lots of looping and parsing when signals emit. This should be a big performance gain.

Hope this helps.

-Luke

0 Kudos
KenGorton
Esri Contributor

Thanks, Luke

I asked because I tested my app in Player on my iPhone and whenever the screen locked after 30 sec without user interaction, the app would stop collecting GPS points. My intent is that it should log GPS positions continuously, storing them in an offline geodatabase and syncing the data back to the feature service periodically even when the device screen is off and/or the app is backgrounded. I assumed my app stopped logging during screen lock because I had not yet configured it to run while backgrounded. Should it have continued to collect GPS data or is there something else I need to do to enable this?

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Ahh, I see. This may be a bit of a limitation with Qt itself at the time. With iOS, it seems that adding the following keys to the plist makes it work. This is true if using Xcode 6, which AppStudio currently is. If using Xcode 7, there are new things you need to do.

<key>UIBackgroundModes</key>

<array>

                <string>location</string>

</array>

For Android, you need to add the following into the manifest

<meta-data android:name="android.app.background_running" android:value="true"/>

The issue seems to be that with Android, if your app is ever backgrounded, it appears that the OS can decide to suspend the app to save battery, and if this happens, the collection would stop. This would require Android services, which are not yet supported in Qt. It looks like Qt is bringing in support for Android services with 5.7, though.

-Luke

0 Kudos