英文:
What is the best way to connect my Android client with a Java app server?
问题
我最近开始学习Android开发,并编写了一个使用Spring MVC的Spring Boot Java应用程序,实现了REST功能。
我想要一些关于如何用Android客户端连接到我的服务器的建议。我是通过Android客户端访问REST控制器吗?
您认为什么是最佳实践,有什么API推荐使用吗?
谢谢您的时间和帮助!
英文:
I have recently begun learning Android development and have written a Spring Boot Java application with REST using Spring MVC.
I would like some advice on how to connect to my server with an android client? Do I hit the REST controller using my android client?
What would you suggest is the best practice and what API would you recommend I use?
Thanks for your time and help!
答案1
得分: 1
根据应用的需求而定。有几种情况下您可能需要应用与服务器之间的通信。
-
HTTP API 调用:
当前端应用程序需要从后端服务器获取一些数据,或者想要作为应用程序功能的一部分将一些数据发送到服务器时,您可以使用诸如 Retrofit 或者 Volley 等任何 HTTP 客户端 API。 -
Websocket:
如果您的应用程序需要双向持续通信,则应优先使用 websocket-client。
在这种情况下,您需要在后端服务器上创建一个套接字端点。 -
推送通知:
推送通知在现代已经非常常见,如果您的服务器希望向您的应用程序传递一些数据,这基本上是从服务器到客户端的单向通信。
这些解释可能会帮助您理解所有可能的情况。
英文:
It depends on the requirement of application. There are several scenario where you want application & server communication.
-
HTTP API call <br/>
When front end application require some data from back end server or want to send some data to the server as part of application functionalities, then you can use any http client APIs like Retrofit or Volley -
Websocket<br/>
If your application needs bidirectional continuos communication then you should pref to use websocket-client
<br/>In this case you need to create a socket end point at your back end server. -
Push Notification<br/>
Push notification is very obvious now days, If your server wants to deliver some data to your application, It is besically one way communication from server to client.
This explanation may help you to understand all possible scenario.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论