views:

64

answers:

1

I'm new to Android and I'm porting an iPhone app I did. I've been reading up on Android services and they look very useful for the network component of my app. I assume there is a common pattern for what I'm trying to do, so here are the details:

  1. User1 and User2 agree to enter a virtual room.
  2. They send messages to each other and get notified when they receive a messages.

I'm using a remote server to handle the communication. So basically, I need three methods. One to add the users to a room, one to send messages and one to get messages. Nothing special.

What I'd like to do is have one service that accepts a few paramaters. One being which web service method to call, the rest being the parameters that need to be passed to the respective web services. I'd prefer this approach to having a different service for each method call. Any suggestions on the best approach? I'm not clear on how to pass parameters to services.

Btw, this is not a question about polling, callbacks or broadcasting. I'm aware of those. I really want to know if it's feasible to pass a variable amount of parameters to a service, or it there is perhaps something else I should look into.

A: 

Sure, read about Intents, Context.sendBroadcast() and BroadcastReceivers. It's quite easy. Sample from out code:

Intent i = new Intent("com.domain.app.intent.STATUS");
i.putExtra("APP", "com.domain.app.android.ActivityOrServiceOfTarget");
i.putExtra("STATUS", "some variable data, e.g. a String");
sendBroadcast(i);
Johannes Weiß
Some good stuff to chew on, thanks!
CYAD