views:

211

answers:

2

Hi,

I'm starting Android doing an application for searching restaurants, and some guidance would be welcome! On the first screen I'd like to have a search field with a submit button (I get the data from a web service), and below a list with the results of the search. When clicking on one of the items of the list it will show a screen with the restaurant details as well as a map showing its location. My questions are:

  • Can I do everything in one single activity or should I do an activity for the search, one for the result list, one for the restaurant description, and another for the map?
  • Would doing one single activity make the application more responsive?
  • How can I use a list and a map within a normal activity (without ListActivity and MapActivity)?

Any help, pointer, example application or sample code is very appreciated!

Thank you

Jul

A: 

I would have an Activity with both the search and list, then another that shows the details of the restuarant.

I don't think it would work well with just a single Activity.

Activities can contain multiple views - a single activity can contain a map and a list if necessary.

ck
Thank you, I'll try with 2 activities.
jul
+6  A: 

Can I do everything in one single activity or should I do an activity for the search, one for the result list, one for the restaurant description, and another for the map?

The answer to this really depends on the flow of your application. I think the most important thing to keep in mind here is how the user will control your app with the "back" button. When you create a new Activity, that puts it on the stack, and the user can always press "back" to pop it from the stack.

One extreme is to put all these steps into different Activities. Then the user has ultimate control using the "back" button, but they might get annoyed jumping around Activities. Putting it all into one Activity is the other extreme, and I highly advise against that; users expect new screens to be a different Activity, one that they can "back" out of, and so if you put all your eggs into one Activity you'll have to start handling "back" yourself.

I think there's a good middle ground that your app could take, though of course your UI design may differ than what I propose. I would say you could do this in two Activities; in the first, you have a search field at the top (with a submit button next to it), and below that search field is a ListView which is populated with results. In the second, you use a TabActivity, where one tab is for the description and the other is for the map. I think this is advantageous for two reasons: on the first Activity, the user sees the results of their search on the same page as the search, and can quickly change the search parameters if necessary. And on the second Activity, the back key encapsulates backing out of one restaurant.

Would doing one single activity make the application more responsive?

Not really. Activities take time to create/tear down, but not that much time. It's better to segment your application in a logical way (for the user experience).

How can I use a list and a map within a normal activity (without ListActivity and MapActivity)?

You can get away with a ListView inside of a normal Activity without ListActivity; just include a ListView in your Activity's content, then in code grab the ListView and set its adapter manually. All ListActivity does is add some handy wrapper functions for one primary ListView, but it's not necessary at all.

Maps are a different matter. You will need to use a MapActivity for displaying maps, because MapActivity has special setup and teardown code that needs to run. Sorry.

Daniel Lew
Thanks a lot Daniel.
jul