Fabrizio Giudici is a Senior Java Architect with a long Java experience in the industrial field. He runs Tidalwave, his own consultancy company, and has contributed to Java success stories in a number of fields, including Formula One. Fabrizio often appears as a speaker at international Java conferences such as JavaOne and Devoxx and is member of JUG Milano and the NetBeans Dream Team. Fabrizio is a DZone MVB and is not an employee of DZone and has posted 67 posts at DZone. You can read more from them at their website. View Full User Profile

A Simple Control Flow Facility For Android Activities

05.16.2010
| 14317 views |
  • submit to reddit
In blueBill Mobile for Android (BTW, I have published the first version to the Android Market) I've had to face with an internal reuse problem. Consider the following diagram, which depicts a couple of possible "screen" flows that the user may navigate within:

In Android, every "screen" is called Activity. The application starts with the ObservationsActivity, which shows the list of recorded observations. By pushing a button, the user can insert a new one. This task is accomplished by a wizard-like flow described by the upper sequence in the diagram:

  1. Eventually pick a bird species from a history list (containing the most recent picks) (PickTaxonActivity).
  2. Alternatively, the user can push a button and get to a new screen where it is possible to browse a taxonomy and drill down to a single species (TaxonBrowserActivity).
  3. Then the number of observed birds and their gender is entered (CountAndGenderActivity). By pressing an "Add more" button, the user might cycle and loop back to entering a new species.
  4. Instead, by pressing an "Ok" button, a final PickLocationActivity allows to enter the location of the observation.
  5. At the end, the user returns to the ObservationsActivity.

In a second function, the user might want to recall a fact sheet of a bird species, with information, media (photos and sounds), etc. It makes sense to reuse the same two activities (PickTaxonActivity and TaxonBrowserActivity) and, after the selection has been done, to get to a FactSheetActivity:

  1. Eventually pick a bird species from a history list (containing the most recent picks) (PickTaxonActivity).
  2. Alternatively, the user can push a button and get to a new screen where it is possible to browse a taxonomy and drill down to a single species (TaxonBrowserActivity).
  3. Then the FactSheetActivity is rendered.
Published at DZone with permission of Fabrizio Giudici, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Casper Bang replied on Mon, 2010/05/17 - 11:52am

That's a very nice pattern, kind of a fluent-interface version of Struts for Android. :) Does this work with Intent filters, i.e. can an Activity have multiple implementations but let the user pick the preferred one? Say I want to write a "plugin" i.e. TaxonByIdActivity for the hardcore birdwatchers who memorized taxonomy ID's?

Fabrizio Giudici replied on Mon, 2010/05/17 - 1:33pm

I've got some extra code that works with Intents, but it's experimental (and probably unneeded for my current requirements). The pattern was born having in mind to solve the problem of direct coupling, but clearly the smart things it does is decoupling navigation decisions - which could end up in Intents as well.

I'm thinking of a similar things that you described, i.e. the capability of extending blueBill with "plugins" that would be delivered as extra application; for instance, a bunch of media providers, that would provide multiple documents available in the internet (or on the local storage) about a certain bird species. This would work with Intents, of course - both letting the user to pick the desired one, or even calling sequentially all the found things and aggregating the results. I've got a tough week, but I'll probably work on that the next weekend.

Fabrizio Giudici replied on Mon, 2010/05/17 - 1:35pm

PS Another thing that I'll soon study is to try to abstract it from Android. In this way, it could be used e.g. for an implementation in JME or JavaFX Mobile - of course, you don't have Activities in those contexts, but you could as well face with a sequence of "screens".

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.