'Roku - Brightscript: Executing a task when the channel is closed using Back or Home Button

Trying to execute a Task when the Channel is closed using Back or Home button. The Task involves calling a url using roUrlTransfer. The urlTransfer.PostFromString(string) gets aborted because the channel is closing. I tried using urlTransfer.AsyncPostFromString(string) too. The call is aborted when the channel is closing.

How does one make the channel to wait for the urlTransfer.PostFromString(string) to complete its work.

What I expect is the Task to complete its work before the Channel is closed!! Instead the urlTransfer.AsyncPostFromString(string) or urlTransfer.PostFromString(string) gets aborted and the Channel is closed



Solution 1:[1]

Roku is far away different in its code architecture than other common programming languages you may know, but not so much complicated as you think.

Keep in mind that if you need to interact with the visual part of an application do it, everything else should be in another thread (use Task), but each task is under the main thread and if you terminate it, it will terminate other sub-threads as well.

Your only option is to handle button presses to catch the BACK button and postpone terminating until it's done, but it will not cover other ways to terminate an application (etc. HOME button).

If you are sending a small amount of data you don't be scared to lose it, it could be delivered even request is not finished.

If you would be more specific I could help you more.

Bests

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lkrocek