Tuesday, June 4, 2013

Re: Pb with activity and events (using gin)

check if the instance of EventBus is the same. I know you have declared it as eagerSingleton in your GIN configuration. But do a quick log to see if the instances are the same.

I remember encountering a similar issue wherein I used to have a new instance of the EventBus getting injected even though I had a similar configuration as yours. In order to fix the problem I had to do the following

1. define a provider

public static class EventBusProvider implements Provider<EventBus> {
private static EventBus bus = null; 

/* (non-Javadoc)
* @see com.google.inject.Provider#get()
*/
@Override
public EventBus get() {
if(null == bus)
bus = new SimpleEventBus();
return bus;
}
}

2. bind

bind(EventBus.class).toProvider(EventBusProvider.class).in(Singleton.class);


On Tue, Jun 4, 2013 at 4:16 PM, Tugdual Huertas <tugdual.huertas@gmail.com> wrote:
Hi all,

i'm facing a litlle problem using places activities and events... Have tried multiple tricks but not luck .

My problem:
i try to fire an event from the activity but my widget does not catch it since its not loaded (I mean that if i fire this event once the widget's loaded everything works fine).

Here is my Gin configuration:

@Override
protected void configure()
{
   bind(EventBus.class).to(SimpleEventBus.class).asEagerSingleton();
   bind(PlaceHistoryMapper.class).to(MyPlaceHistoryMapper.class).in(Singleton.class);
   bind(ActivityMapper.class).to(MyActivityMapper.class).in(Singleton.class);
   bind(MyActivity.class);
   install(new GinFactoryModuleBuilder().build(MyActivityMapper.Factory.class));
}

@Provides
@Singleton
public PlaceController getPlaceController(EventBus eventBus)
{
   return new PlaceController(eventBus);
}

@Singleton
@Provides
public ActivityManager provideActivityManager(ActivityMapper activityMapper, EventBus eventBus)
{
   return new ActivityManager(activityMapper, eventBus);
}

in MyActivity:
@Inject
private MyWidget myWidget;
@Inject
private EventBus globalEventBus;

@Override
public void start(AcceptsOneWidget panel, EventBus eventBus)
{
   panel.setWidget(myWidget);
   MyEvent event = new MyEvent();
   event.setAction(MyEvent.Action.INIT);
   globalEventBus.fireEvent(event);
}

I also try two different ways of binding events in my widget, during onLoad and in constructor:

During onLoad:

@Inject EventBus eventBus;

@Override
protected void onLoad()
{
   handlersRegistration.add(eventBus.addHandler(MyEvent.TYPE, this));
}


In constructor:

private EventBus eventBus;

@Inject
public MyWidget(EventBus eventBus)
{
   this.eventBus = eventBus;
   // registration of handlers
   handlersRegistration = new ArrayList<HandlerRegistration>();
   // register myself has a listener of different event TYPE
   handlersRegistration.add(eventBus.addHandler(MyEvent.TYPE, this));
   
   ...
}


Am I doing something w rong or missing something?

Thks in advance

Tugdual

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
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.
 
 

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
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.
 
 

No comments:

Post a Comment