Proper flow charting would help with your coding design.
A) You can download all the xml you like in the Main thread, before Scenegraph executes
or
B) You can download the xml in the main thread before scenegraph executes, do your branch in the main thread, execute scenegraph, when the user exits that it goes back to the main threead and downloads again and starts scenegraph the other way you want
or
C) You can simply start up scenegraph immediately in the main thread without downloading anything, when your first screen is visible in scenegraph download in a task node and parse the xml and create the display in scenegraph as required for the branch
A simple task node configuration -
<?xml version="1.0" encoding="utf-8" ?>
<!--********** Copyright 2015 Roku Corp. All Rights Reserved. **********-->
<component name="taskdownloaddata" extends="Task">
<interface>
<field id="uri" type="uri" />
<field id="content" type="node" />
</interface>
<script type="text/brightscript" uri="pkg:/components/screens/TaskDownloadData/taskdownloaddata.brs"/>
</component>
And the brs
Sub init()
m.top.FunctionName="getNewData"
End Sub
Sub getNewData()
readInternet=createObject("roUrlTransfer")
readInternet.setUrl(m.top.uri)
source=readInternet.GetToString()
If Len(Source)>10 'Something is here to parse
content=createObject("roSGNode","ContentNode")
contentxml=createObject("roXMLElement")
contentxml=parseJSON(source)
row=CreateObject("RoSGNode","ContentNode")
row.title=contentxml["category name"]
If contentxml.entry.count()>0
cd=contentxml.entry[0]
y=cd.count()-1
For z=0 To y
item=CreateObject("RoSGNode","ContentNode")
item.SetFields(cd[z])
row.AppendChild(item)
Next
End If
content.AppendChild(row)
m.top.content=content
End If
End Sub
Basically you are just creating a task node, moving the code you would have used in main to download the xml into the task node, and setting up a way to stick in a URL and grab out the retrieved data back into the render thread where you display it.