Android服务架构问题(Android service architecture question)

编程入门 行业动态 更新时间:2024-10-21 09:14:02
Android服务架构问题(Android service architecture question)

我是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);

更多推荐

本文发布于:2023-08-06 23:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:架构   Android   service   question   architecture

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!