在Android的评论屏幕上实施网络呼叫的最佳做法如何?

[英]How are the best practices to implement network calls on a comments screen on Android?


I have to do a comments screen, and I don't want to block the user while the network call is running, so, I am thinking about how can I manage a way where the user can write something, click the send button, and repeat this process lots of times, putting the items in the comments list, then making the calls and if it failed, shows a try again button just in the items where the fail happens. What I'm thinking to do, is, create a recursive method to treat the call, and every time the user click the send button, I add the comment to a list, and the call method will do itself until the list is empty. But, if the fail happens just for one comment, for example, how can I know the comment where I have to show the try again button? And, there's a better way to do this? I'm using Retrofit.

我必须做一个评论屏幕,我不想在网络呼叫运行时阻止用户,因此,我在考虑如何管理用户可以写东西的方式,单击发送按钮,以及多次重复此过程,将项目放在注释列表中,然后进行调用,如果失败,则会在失败发生的项目中再次显示“尝试”按钮。我想要做的是,创建一个递归方法来处理调用,每次用户单击发送按钮时,我都会将注释添加到列表中,并且调用方法将自行执行,直到列表为空。但是,如果仅针对一条评论发生失败,例如,如何知道我必须再次显示试用按钮的评论?而且,还有更好的方法吗?我正在使用Retrofit。

1 个解决方案

#1


0  

THe standard way of doing this is to create a Thread and have a synchronized list of messages to send. When you press a button, you add an item to the list. The thread will have an infinite loop, reading the top item from the list (or sleeping until its non-empty) and processing it (sending it to the server in this case).

执行此操作的标准方法是创建一个Thread并具有要发送的消息的同步列表。按下按钮时,会将项目添加到列表中。线程将有一个无限循环,从列表中读取顶部项目(或睡眠直到其非空)并处理它(在这种情况下将其发送到服务器)。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/06/24/a08c848e487d7cd38ac3c31e4abfb2d2.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com