Issue: Multiple Presenter Instances

44 views
Skip to first unread message

Cassio

unread,
Feb 22, 2012, 5:38:11 PM2/22/12
to google-we...@googlegroups.com
Hey, I am using a similar project structure as the MVP architecture example (Presenter with nested Display interface)

When I use the History and Tokens to navigate between Views, there is always a new Presenter being created linking to the single View.

This now causes my problem: When I click a button in the View that event is being processed by all the Presenters that were created before.

Am I missing something? Or how do I avoid this?

Thanks.

Thomas Broyer

unread,
Feb 23, 2012, 4:09:39 AM2/23/12
to google-we...@googlegroups.com
When you attach a new presenter to a view, it should *replace* the previous one, so you have to find a way to do this.

if you follow the "part 2" article from the docs, the one with a Presenter interface in addition to the Display interface, then it's straightforward.
If you don't, but you're using Activities (and your activity is your presenter), then you'll have a clear onStop() hook signaling your presenter when to un-register its event handlers.
Otherwise, you'll have to come up with something similar.

I can't express how strongly I'd suggest you use Places and Activities for navigation (rather than History and tokens), and the "part 2" approach for binding your presenter(s) to the view (call setPresenter on the view from your activity's start() method, and possibly call setPresenter(null) from onStop and onCancel)

Cassio

unread,
Feb 23, 2012, 12:58:57 PM2/23/12
to google-we...@googlegroups.com
Thank you,

I think I'll go for that second way of handling this.

 I'll also take a look into Places and Activities. Is there a bigger example project around than "Tutorial-hellomvp-2.1"?

Thomas Broyer

unread,
Feb 24, 2012, 4:46:09 AM2/24/12
to google-we...@googlegroups.com
Have a look at the MobileWebApp sample from the GWT SDK (if you installed the SDK as an Eclipse plugin, you should find the samples within your Eclipse install path; otherwise, just download the GWT SDK from http://gwt.google.com )
Reply all
Reply to author
Forward
0 new messages