Skip to main content
Participant
May 1, 2011
Question

MobileApplication / View / Navigator issue

  • May 1, 2011
  • 1 reply
  • 677 views

I've ran into an issue I can't seem to resolve. I have a main view with a Label and a Timer. The timer executes once a second and updates the label with the current time. All is great.

But,

If I hit a button to go to another view via navigator.pushview(SecondView) I can still see the timer is still running via trace/console.

On the second view I press a button and call navigator.popView to go back to the previous page.


Now, the timer is still running, I can still see the timer event being called but now the Label is no longer being updated with the time, it simply shows the default initalized value.

Can someone please shed some light on this. I really need to be able to return to the first view and have it operating just like I left it.

Tom

This topic has been closed for replies.

1 reply

Inspiring
May 2, 2011

Unlike the ViewStack in desktop flash, a ViewNavigator only ever has one child in memory at a time. What that means is that when you push a new view on to the view navigator, the existing view is eligible for garbage collection.  When you pop the second view, you are not returned to that view you saw originally, a new one is created.

The real problem exists because there are event listeners tied to that view, it will never be Garbage Collected (as I understand it ) and so you will always continue to see those events fire.

Knowing how this works what you need to do is utilize the activate and deactivate events of the View to setup and destroy your timer object.  I have written an example of this and posted it on github.

Take a look at this and see if it helps you sort out how your view should work.

https://gist.github.com/951965

HTH,

sim