Basic question on activity and places

58 views
Skip to first unread message

sri

unread,
Jan 3, 2012, 1:40:56 PM1/3/12
to Google Web Toolkit
Hello,
Is there a best practice when defining Places and Activities. Are
Places and Activities one-to-one? If that's not true and there are
multiple activities with a single Place, does the ActivityMapper
return a default Activity when going to a new place. Most of the
articles I have read indicates a one-to-one between Activities and
Views, but does not mention between Place and Activity. Thanks in
advance.

-sri

Jens

unread,
Jan 3, 2012, 2:26:00 PM1/3/12
to google-we...@googlegroups.com
If you have multiple display areas in your app you would have multiple ActivityMappers (one per display area, e.g. a master area and a detail area). Now if you go to a Place each ActivityMapper can return a different Activity based on the Place. So its more like one-to-<number of activity mappers>. A common example is that you have a ListEmailActivity that shows a list of emails and a EMailDetailsActivity that actually shows the selected email's content. Both can be started at the same time if the list of emails and the contents of the selected email are visible at the same time. If an ActivityMapper does not need to return an Activity for a place it can return null or return a default Activity that displays a message or something. You could use both methods, e.g. if you return null it means "hide the entire display area because I don't need it for that place" and if you want to show a message return a MessageActivity instead.

It can also happen that an ActivityMapper can start the same Activity for different places. For example you could have a single ListActivity that defines a general set of features for a list style view (for example searching the list, list ordering, etc.) but uses a ListAdapter to manage the displayed objects. If you now have EmailListPlace, PersonListPlace, etc. they all would start a ListActivity but for each Place the ListActivity would use a different ListAdapter, e.g. EmailAdapter, PersonAdapter, etc. 

-- J.

sampath sai

unread,
Jan 3, 2012, 4:39:16 PM1/3/12
to google-we...@googlegroups.com

Hi Jens,

I have question on activities. I have multiple areas like Master and Detail. Cell table will display data in master, when I select row in the master, I can going to detail place. But problem is again master activity mapper is being invoked. Please help.

Thanks in advance,

Sai


--
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/-/ahsrTNbpg8gJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Thomas Broyer

unread,
Jan 3, 2012, 5:46:09 PM1/3/12
to google-we...@googlegroups.com
Return the exact same instance and your activity won't be "restarted". CachingActivityMapper and FilterActivityMapper can help here.

sampath sai

unread,
Jan 3, 2012, 6:27:55 PM1/3/12
to google-we...@googlegroups.com
Hi Thomas,

Is their any way to find out, what is current activity running or displaying. so for that place, i can decide, if i need change for place, i can decide to send it or not.

Sai

On Tue, Jan 3, 2012 at 2:46 PM, Thomas Broyer <t.br...@gmail.com> wrote:
Return the exact same instance and your activity won't be "restarted". CachingActivityMapper and FilterActivityMapper can help here.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Thomas Broyer

unread,
Jan 4, 2012, 5:10:41 AM1/4/12
to google-we...@googlegroups.com
No, but you can store the last activity you returned; this is exactly what the CachingActivityMapper does: it'll only call your (wrapped) ActivityMapper if the Place is different than the previous one, and returned the "cached" activity otherwise.
Put it behind a FilteredActivityMapper so you can turn different Places to other ones that could compare equal (e.g. turn any EmailDetailsPlace into a EmailListPlace, and every PersonDetailsPlace into a PersonListPlace; so that the CachingActivityMapper can return the same EmailListActivity or PersonListActivity ("master") instance whereas you're navigating from mail to mail or person to person ("detail to detail")).

sri

unread,
Jan 4, 2012, 8:05:29 AM1/4/12
to Google Web Toolkit
Thanks Jens.
A quick followup question.
You have mentioned Display Area. From the response, I take it a Place
is bigger than a display area and multiple Display Areas make up a
place.right?
So if there is one ActivityMapper per Display Area, which would
indicate multiple ActivityMappers per Place, which component is
responsible for deciding which ActivityMapper be used when you are in
a Place? Thanks.

-sri

Jens

unread,
Jan 4, 2012, 9:14:39 AM1/4/12
to google-we...@googlegroups.com
A quick followup question.
You have mentioned Display Area. From the response, I take it a Place
is bigger than a display area and multiple Display Areas make up a
place.right?

Yes, you could say it that way. 

A place is just an abstract tool that allows you to navigate through your app and storing state information. It has no real relation to display areas. A place does not know anything about display areas. You could have one, five or ten display areas. 

Imagine you are in a plane flying around the world. If the plane has three windows (front, left, right) you would see something different through each window (= display area). What you see depends on where you are (= place). But the place doesn't care about if you are in a plane looking through the left window ;-)
 

So if there is one ActivityMapper per Display Area, which would
indicate multiple ActivityMappers per Place, which component is
responsible for deciding which ActivityMapper be used when you are in
a Place?


When you change a place a PlaceChangeRequestEvent is fired on the EventBus and if the place change is allowed a PlaceChangeEvent is fired after it. For each display area you have to set up an ActivityManager (manages activity life cycle and clears the display area if the activity is stopped) which needs an ActivityMapper and an EventBus. So the ActivityManager listens for PlaceChange(Request)Events on the EventBus and ask the ActivityMapper for the activity it should use for a given place.

So in your app's init method you would have some code like:

EventBus eventbus = ....;
ActivityManager masterActivityManager = new ActivityManager(new MasterActivityMapper(), eventbus);
masterActivityManager.setDisplay(appShell.getMasterDisplayArea());

ActivityManager detailsActivityManager = new ActivityManager(new DetailsActivityMapper(), eventbus);
detailsActivityManager.setDisplay(appShell.getDetailsDisplayArea());

Now on a place change the ActivityManagers act totally independent from each other. But as you are responsible for implementing the ActivityMappers you can decide what each display area should show for a given place by returning the activity you want. So the component that decides which ActivityMapper is used is the developer that writes the app's init method ;-) 

-- J.

Thomas Broyer

unread,
Jan 4, 2012, 11:22:26 AM1/4/12
to google-we...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages