Languages

Menu
Sites
Language
[SOLVED] [Q] On-initial OnSceneActivatedN(), on-destroy OnSceneDeactivated().

Hi,

Any way to tell the on-initial (first-time) OnSceneActivatedN() and the on-destroy (last-time) OnSceneDeactivated()? I need to execute some specialized code only when a Scene is activated for the first time and only when a Scene will be destroyed.

The problem is that OnSceneActivatedN() is invoked when creating a Scene (SceneManager::GoForward(...)) and when getting back to an underlying Scene (SceneManager::GoBackward(...)). Similarly, OnSceneDeactivated() is invoked when a new Scene will cover an underlying Scene and when a Scene will be destroyed.

There is no way to get that information from Scene history, nor there is a way to access SceneTransition (direction) from within OnSceneActivatedN() and OnSceneDeactivated().

Ideas?

Gary

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

5 Replies
Set pArgs in OnSceneActivatedN when you go back. if(pArgs == null){ //first time }else{ //coming from GoBackward() }
Gary V
Thanks for the reply. Good idea for OnSceneActivatedN(), but unfortunately OnSceneDeactivated() cannot receive any arguments. Gary
Alex Dem
Hi, Maybe you could use OnInitializing/OnTerminating of your Form (or another container) which placed on Scene. For on-initial (first-time) OnSceneActivatedN() you could use this primitive way in OnSceneActivatedN : to add member isFirstTime into class, and set it true. if (isFirstTime) { isFirstTime=false; } Alexey.
Gary V
Thanks for the reply. Unfortunately, Form::OnInitializing() is called BEFORE OnSceneActivatedN() (so the first time around a special flag would already be set) and Form::OnTerminating() is called AFTER OnSceneDeactivated() (so the last time around a special flag would not be set yet). OnSceneActivatedN() could also be handled by keeping a "map" of all Form objects already initialized, but there seems to be no way to know whether a particular OnSceneDeactivated() is the very last one before Form::destructor. Gary
Gary V
FYI, a solution: 1.) SceneManager::GoForward() is "standardized" as always invoked with at least one (zero-count, but non-null) argument ListArray. SceneManager::GoBackward() is "standardized" as always invoked without a null argument ListArray. ISceneEventListener::OnSceneActivatedN() with a non-null argument Tizen::Base::Collection::IList indicates an on-initial-update condition. 2.) Before calling SceneManager::GoBackward(), a Tizen::Ui::Controls::Form subclass is "standardized" as set with an internal boolean flag, with a IsTerminating() accessor. ISceneEventListener::OnSceneDeactivated() can obtain the Form through SceneManager::GetCurrentScene() + Scene::GetForm() - and query the flag. The sequence of events is: Form::SetIsTerminating(true) >> SceneManager::GoBackward() >> ISceneEventListener::OnSceneDeactivated() - Form::IsTerminating() >> Form::OnTerminating() >> Form::destructor. That's why a flag has to be set manually before SceneManager::GoBackward(). Form::IsTerminating() happens AFTER ISceneEventListener::OnSceneDeactivated(), there is no way to fully automate. Not the prettiest stuff, but I found no other simple solutions. Thanks for the suggestions! Gary