On Wednesday, November 9, 2011 4:59:12 PM UTC+1, tanteanni wrote:
>
> thx for clarification jens.
>
> my problem is that i use the event bus within some activities outside of
> start(..) and there i always should use the bindary-One. So in such
> activities i have two different EventBuses. the bindary-One is imported the
> other one is explicitly set in start method.
>
Out of curiosity, why should you "always use the web.bindery one"?
Either you add handlers to it, and using the global bus directly could be a
source of memory leaks (you forget to remove your handlers, and the bus
then keeps holding references to your activity, even after it's stopped and
supposedly disposed), adding your handlers to the bus passed to the start
method would have the same effect re. your handlers, except that they're
automatically removed when the activity is stopped (onStop or onCancel) so
you're guaranteed to not leak.
Or you fire events, and then again, the bus passed to the start method will
simply delegate to the global bus (the one passed to the ActivityManager),
so it's not an issue either. Even after the activity is stop you can still
fire events on that bus (if for instance you do it from AsyncCallbacks or
Receivers; e.g. the user clicks "save" then navigates before the server
responds, maybe you ask him to confirm –return a non-null value from
maybeStop– but he chooses to go away nonetheless, so the activity is
stopped; when the server responds, you can still fire an event on the bus,
for instance to show a notification that the object has correctly be saved).
Oh, and the field in your activity holding the eventbus can still use the
web.bindery type, as the gwt bus extends the web.bindery one:
import com.google.web.bindery.event.shared.EventBus;
class MyActivity extends AbstractActivity {
EventBus bus;
@Override
public void start(AcceptsOneWidget panel,
com.google.gwt.event.shared.EventBus bus) {
this.bus = bus;
// do your initialization stuff
}
private void fireFooEvent() {
this.bus.fireEvent(new FooEvent());
}
}
And to be sure that an activity never uses /imports the wrong EventBus i
> did it in all activities. (someone could add some code to an activity that
> uses/needs an eventbus and if at this point in time the wrong import is
> present (because the start -method needs it) it won't work - some injector
> error will occur)
>
To make sure you don't use/import the wrong event bus, simply watch for
"import com.google.gwt.event.shared." in your files (except if you're
importing GwtEvent); in most cases, I guess you'll have type mismatch
errors (trying to assign a web.bindery bus to a gwt variable) or
deprecation warnings (if you have a variable of type "gwt EventBus", then
the compiler will resolve constructor/method overloads using that bus too,
which are deprecated as you noted earlier: ActivityManager,
PlaceController, etc.)
And of course, watch for these errors when compiling: "Rebind result
'com.google.gwt.event.shared.EventBus' cannot be abstract" ;-)
(I unfortunately don't have any real experience on this though, as we're
stuck with an old version of GWT before things were moved to web.bindery;
too many customizations –yes, you could say "abuses"– of RF that make it
hard to update)
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/wl21K36FcP0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.