Hi,
 I am using Activity classes and event handlers as follows and I am not 
sure if my understanding is correct. Hence the post.

1. I understand that Activity instances are disposable but view instances 
are not. 

2. As a result of a place change, my ActivityMapper creates a new Activity 
instance:
           if (place instanceof LoginPlace)
              return new LoginActivity((LoginPlace) place, clientFactory);

Question: While it is true that Activity is supposed to be disposable, is 
it really a good idea to create a new instance instead of reusing an 
existing one? I.e. is it better to just do clientFactory.getHomeActivity()?


3. In the constructor of my activity, I add event handlers. For example:
clientFactory.getEventBus().addHandler(LoginEvent.TYPE, new 
LoginEventHandler(){
public void onEvent(LoginEvent event) {
System.out.print("Got login event "+event.getLoggedInUser()+" 
"+event.getFailureMessage());
if(!event.isAuthenticated()){
Window.alert(event.getFailureMessage());
}
}
}); 

Now, as per the JavaDoc documentation of Activity, 

Any handlers attached to the provided event bus will be de-registered when 
the activity is stopped, so activities will rarely need to hold on to the 
HandlerRegistration<http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/event/shared/HandlerRegistration.html>
 instances 
returned byEventBus.addHandler(com.google.gwt.event.shared.GwtEvent.Type, 
H)<http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/event/shared/EventBus.html#addHandler(com.google.gwt.event.shared.GwtEvent.Type,
 
H)>.

So, what I understand is that in the mayStop() method of my activity, I 
don't have to do anything wrt the event handler. If the user goes back to 
the same activity again, a new Activity instance will be created and a new 
handler will be registered (since that code is in the constructor). The old 
registration is automatically cleaned up.

I just want to confirm this because it seems asymmetric. In general, if I 
register an event handler explicitly it is my responsibility to un-register 
it. But here it is being cleaned up automatically. 
This ties back to the previous question that if the handler is being 
removed automatically, then I have no option but to create another instance 
of Activity (or at least re-register the handler),

Could some one please let me know how am I doing?

thank you,
Andy.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to