Currently there is no provision in brightscript to perform cleanup tasks when the application is closed, however some of the tasks need to be performed at a highest priority.
While integrating a channel (that plays videos) with google analytics, I want to track the amount of time for which a particular video has been played, for which need to fire an event as soon as the channel is stopped.
However, it seems impossible to track the app close event, (with reference to previous topics based , it was possible in firmware 3.1). Currently thinking of writing time for which a video was played into roRegistrySection, reading the contents back from the registry section while the next time app is started again to see for what time the video was played.
the
pseudo code (not the actual snippet) goes like this :
while the app starts
check the registry for the cleanup flag ' cleanup flag is the flag which if set, the google analytics event relating to the video play time was not fired
if the flag is set
read the time for which the video was played from the registry
fire the event
else continue with the regular activities
I do not see a reason why the above pseudo code will not work.
However, the performance onus to
log the time into the registry for the step
read the time for which the video was played from the registry would have tremendous performance onus.
I want the precision to be of one second, for which I will have to
write to registry modifying the 'time played ' key for every second of video played. With reference to "
Flushing the registry is a relatively time-consuming operation, so it should be done as infrequently as possible." over
http://sdkdocs.roku.com/display/sdkdoc/roRegistrySection , this could be a disaster.
The app would be snail slow if I keep flushing the registry every second of video played.
Is registry_section.write() inexpensive compared to registry_section.flush() ? and is registry_section.flush() automatically called when the app is closed ? if that is the case, the above approach might work.
Any help would be greatly appreciated.
-Batheja Sumeet