如何在 Android 中创建聊天屏幕?

发布于 2024-12-21 19:19:51 字数 107 浏览 3 评论 0原文

我正在创建一个 Android 聊天应用程序。我希望聊天屏幕包含一些功能,例如用于与不同用户聊天的新 UI 屏幕。但我不知道如何进一步推进。我应该使用服务还是异步任务或者还有其他方式吗?请帮助我开始。

I'm creating an Android chat application. I want chat screen to include features like a new UI screen for chat thread with a different user. But I don't know to move further with it. Should I use service or asyntask or is there any other way. Please help me get started.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲喜皆因你 2024-12-28 19:19:51

不。如果您为每个用户使用每个线程,您将产生许多线程(内存、创建和清除的时间......)。

当接收消息时,您应该使用一个服务来侦听(通过使用意图,这是一项简单的工作),并且您可以在主 UI 线程中执行此操作。

No. if you use each thread for each user, you will spawn many threads (memory, and time to create and clear...).

You should use a service to listen when receive message (this is an easy work by using intent), and you can do in your main UI Thread.

生寂 2024-12-28 19:19:51

一旦活动关闭,聊天就会关闭(与服务器/用户正在聊天的另一个设备的网络连接),所以我不认为有理由使用服务/AsyncTask。只需有一个线程等待来自套接字流的数据,并在数据到达后向用户显示该数据。

The chat gets closed (The network connection with the server/another device which the user was chatting with) once the activity closes, so I don't see a reason to use a serivce/AsyncTask. Just have a thread waiting for data from the socket streams, and show that data to the user once it arrives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文