1

I'm writing an application with 3 mapactivities, and i've implemended a local service(like google tutorial) that recives update from location manager, to share location data from gps between these activities. Now i want to put every activity in separated process to follow google's suggestion.

So my question is how I have to proced?? Implement and AIDL interface for remote services or register every mapactivity to location listener??

Thanks for answers and sorry for my bad english :P

IncioDev
  • 11
  • 4
  • What "Google's suggestion" are you talking about? Can you give an URL for that? – mikołak Jan 08 '12 at 14:59
  • [link](http://code.google.com/intl/it-IT/android/add-ons/google-apis/reference/com/google/android/maps/MapActivity.html) Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways. – IncioDev Jan 08 '12 at 15:14
  • Oh, I see now. My answer is coming up... – mikołak Jan 08 '12 at 16:11

3 Answers3

0

If it's just a single application that needs location information, then using a remote service and AIDL is an unnecessary complication. The easiest way would be to have a local service with which the activities can bind, then have the service use sendBroadcast() to send location information. The activities can then register a BroadcastReceiver to pick up this data.

NickT
  • 23,844
  • 11
  • 78
  • 121
  • Now i'm using a local service that send a broadcast every time location is update and then the activity take data using service's method. But when i put map activity in separeted process i have an error of cast class exception when i return an istance of the service to give activity the possibility to call service method.. from this the idea of remote service.. – IncioDev Jan 08 '12 at 15:10
0

First the rationale:

That quote in the Javadoc is a bit... weird. If you understand "running" as being between onResume() and onPause(), then normally two Activities belonging to the same Application cannot "run simultaneously". You would probably have to mess with the Application class or the OS itself to have it behave otherwise.

To wit, I'm actually developing an app at the moment that uses several MapActivity subclasses and haven't encountered any problems so far (i.e. 40+h of development and testing, both on emulators and a device).


Therefore I would suggest:

  1. Try to implement your app as a single-process activity with a local service and just run with it.
  2. If you don't want to do that (can't blame you ;) ), or you encounter any problems, I would suggest starting out with a MapView, perhaps encapsulated within a Fragment. Here's a discussion to get you started.

In short, due to Android's practical fragmentation, keeping your Activities in one process and commiting more time by starting with a more bare-bones implementation will be a safer, ultimately less time-consuming and probably more efficient approach than artificially splitting your app and potentially gritting your teeth on the IPC. At least in my opinion.

mikołak
  • 9,605
  • 1
  • 48
  • 70
  • Now the app structure is exactly as you suggested. MapActivity has a bounded local service. the service send broadcast intent and the activity can access service method like the Local Service Sample on Android tutorial.. I've catched this warning IllegalStateException Connection pool shutdown.. do you know something about that? – IncioDev Jan 08 '12 at 16:52
  • Well, haven't encountered it myself, but it looks I may be lucky: http://code.google.com/p/android/issues/detail?id=3756 Look at the last posts, #21 specifically. To be honest, I have no idea why I haven't encountered this problem - may be because most of my activities don't do much with the view, but that's speculation. – mikołak Jan 08 '12 at 17:04
0

After some research i think the best way is to implement IPC with a messenger like described in Android doc http://developer.android.com/guide/topics/fundamentals/bound-services.html#Messenger.. I'll test this solution an report here the result..

Best tutorial is http://developer.android.com/reference/android/app/Service.html#RemoteMessengerServiceSample where is implemented a 2 way communication from client and service..

IncioDev
  • 11
  • 4