Using non disposable activities extracting parameters from a place

21 views
Skip to first unread message

l.denardo

unread,
Feb 23, 2012, 7:22:38 AM2/23/12
to Google Web Toolkit
Hello,
I'm facing a problem with activities and places.
My use case is quite simple.

I have more kind of places in my app (e.g. CalendarPlace and
ResourcePlace). Each place can contain the ID of a given object.
When I switch place I want to load the correct editor for the kind of
object (switching if place type has changed) AND init it with the
correct value.

I use two activities to accomplish this. CalendarActivity and
ResourceActivity.
My ActivityMapper selects the correct kind, extracts the object ID
from the current Place and sets it on the correct Activity, then
returns it.

I load the details of the object on each activity's start(...) method.

My problem is that the two activities are actually singletons (not-
disposable), since they have different dependencies injected through
GIN.
In this case the ActivityManager (line 114) does NOT fire a start(...)
on the activity after the place has changed.
My place switch works fine when activity kind changes, but not when
the activity is the same but objectId has changed.

i.e calendar13 --> resource 14 is fine, and resource14 is loaded
resource14 --> resource15 is not: start is not called so resource15 is
not loaded

I wonder what is the best way to have a correct state change when
place chages occur.
*Build a GIN provider or the like for activities and have a different
Activity object returned each time
*Do the "new object" loading immediately when the ActivityMapper calls
the setter instead of the start(...) method
*Any other way?

I noticed things can be mixed reading
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/d827400bda6b996b/4367bbcc2d36aa5c?lnk=gst&q=reuse+activity#4367bbcc2d36aa5c
but I wonder if there's a suggested way to work around this.

Thanks for your help
Lorenzo

Thomas Broyer

unread,
Feb 23, 2012, 9:15:39 AM2/23/12
to google-we...@googlegroups.com


On Thursday, February 23, 2012 1:22:38 PM UTC+1, l.denardo wrote:
My problem is that the two activities are actually singletons (not-
disposable), since they have different dependencies injected through
GIN.

If this is the only reason, then it's not a good reason. It's too easy to not use singletons with GIN to not take advantage of it: replace your dependency on CalendarActivity to a dependency on Provider<CalendarActivity> in your ActivityMapper (same for ResourceActivity) and you're done, and you'd have eliminated your issue at the same time.

I wonder what is the best way to have a correct state change when
place chages occur.
*Build a GIN provider or the like for activities and have a different
Activity object returned each time

Definitely (unless you have a good reason to do otherwise)
 
*Do the "new object" loading immediately when the ActivityMapper calls
the setter instead of the start(...) method
*Any other way?

Tracker whether the activity is started or not (as I said on some other similar thread in the past few weeks, this is something you should already be doing anyway IMO) to determine what to do when the setter is called: either wait for the activity to be started, or start loading the data right away if the activity is already "live and running".

l.denardo

unread,
Feb 23, 2012, 11:30:17 AM2/23/12
to Google Web Toolkit
Thank you Thomas!

I ended up doing something similar to what you say, moving GIN
injected dependencies into my ActivityMapper and using them to build a
new Activity (I'll switch to a provider as soon as possible).
I actually ended up subclassing ActivityManager (and extending
Activity itself) to provide a different switching behavior, since I
had some needs for optimization.
Maybe I'll go back to the default as I clean up my own code using the
Places/Activity architecture (I'm on an hand-made MVP, with no place
tight behavior, by now).

Thanks very much for your collaboration (and of course for your blog
posts on the whole framework, I found them way clearer than the
official documentation on this matter).

Regards
Lorenzo
Reply all
Reply to author
Forward
0 new messages