Android service architecture question
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:
- User1 and User2 agree to enter a virtual room.
- 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 approac开发者_JS百科h 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.
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);
精彩评论