我是Android新手,我正在移植我做过的iPhone应用程序。 我一直在阅读Android服务,它们看起来对我的应用程序的网络组件非常有用。 我假设我正在尝试做一个共同的模式,所以这里有详细信息:
User1和User2同意进入虚拟房间。 他们互相发送消息,并在收到消息时收到通知。我正在使用远程服务器来处理通信。 基本上,我需要三种方法。 一个用户将用户添加到一个房间,一个用于发送消息,一个用于获取消息。 没什么特别的。
我想做的是有一项接受一些参数的服务。 一个是要调用的Web服务方法,其余是需要传递给相应Web服务的参数。 我更喜欢这种方法为每个方法调用提供不同的服务。 关于最佳方法的任何建议? 我不清楚如何将参数传递给服务。
顺便说一句,这不是关于民意调查,回调或广播的问题。 我知道那些。 我真的想知道将可变数量的参数传递给服务是否可行,或者我可能会考虑其他的东西。
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 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.
最满意答案
当然,请阅读有关Intent , Context.sendBroadcast()和BroadcastReceiver的内容。 这很容易。 来自外码的样本:
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);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);更多推荐
发布评论