3

I'm a relatively experienced .NET/iOS developer taking first steps in Android development - to help me avoid going down the wrong path I'd be grateful for some guidance:

Essentially, I have an app that displays locations on a map/list. As the user scrolls around the map, the locations are fetched from a JSON web service. A location can be tapped, at which point another JSON web service is called to retrieve live information for that location. The live info is then displayed.

So, having read the various 'getting started' Android docs, I would imagine I need:

  1. An Activity to display the main map view of the locations
  2. A second Activity to display the list view? These seems odd since I get the impression that each Activity has to be an entire screen of the app. I'd like to persist the other UI elements. (e.g. button to switch views, button for settings etc) Is this possible?
  3. A Service (or IntentService?) to retrieve the locations from the web. How should it let the Activity and ContentProvider know when new locations have been retrieved - via Broadcasts or should they bind to it?
  4. A ContentProvider, to cache and persist my locations. Perhaps the content provider should broadcast to the activities when new data is available to display?

Your help would be very much appreciated, since I feel a little lost!

Carlos

PS: I'll be developing with Mono for Android, unless enough people advise against

Carlos P
  • 3,928
  • 2
  • 34
  • 50

3 Answers3

1
  1. Points 1 and 2 : You could use Fragments to update part of the screen, Activity will act as a container for multiple fragments ( use compatibility library for back porting fragments to API level 10 or less

  2. You should use AsyncTask instead of a service to get the locations from a remote web service

  3. AsyncTask has a callback onPostExecute(..) which will be called on completion of remote fetch, this can be used to update List, Maps or Fragments

Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22
1

1 . You can use MapActivity for map view;

2 . use Activity and place listView to include button in a single view instead of ListActiviy

3 .please follow the link for location updator tutorial

http://www.vogella.de/articles/AndroidLocationAPI/article.html

4 . use map overlay technique for your message display

please make comments if u want any suggestions further after u go through it

Noufal Panolan
  • 1,357
  • 2
  • 14
  • 27
1

An Activity to display the main map view of the locations

Yes

A second Activity to display the list view? These seems odd since I get the impression that each Activity has to be an entire screen of the app. I'd like to persist the other UI elements. (e.g. button to switch views, button for settings etc) Is this possible?

Not necessarily so. Take a look at the Fragments API. It allows you to switch only parts of your UI. It was introduced in Android 3.0, but there exists an official backport of it, so that you can also use it in previous Android versions.

With it, you can put your buttons into the activity, the map in one fragment and the list in another, and then just switch the map with list while retaining the buttons.

A Service (or IntentService?) to retrieve the locations from the web. How should it let the Activity and ContentProvider know when new locations have been retrieved - via Broadcasts or should they bind to it?

I would strongly advice against this. You should use a service if you have long-lasting downloads in the background, like downloading a file or something. Short term JSON requests can and should be handled in the UI process. Use AsyncTask or an Executor for that. There has been advice by Google to put almost all of your requests into a service, but believe me, it's bull.

A ContentProvider, to cache and persist my locations. Perhaps the content provider should broadcast to the activities when new data is available to display?

Not required. You only really need a ContentProvider if you plan to make your content accessible to other Applications or the System. For HTTP caching, you can directly access the database/filesystem, or better yet, use the Apache HTTP Client Cache. Works well if you use the already embedded Apache HTTP Client, which you should.

Timo Ohr
  • 7,947
  • 2
  • 30
  • 20
  • thanks, that's very comprehensive. Couple of questions: (1) I mentioned that I'm using Mono, do you know whether a backport would be compatible with this approach. And (2) If I don't use a ContentProvider, still slightly confused as to how I'd create the data layer; would I use a singleton class that serializes/deserializes objects to the database? Essentially, each location object has various fields associated with it (e.g. lat/long/name) that need saving to the DB so they can persist between loads of the app. – Carlos P Dec 09 '11 at 13:16