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并具有要发送的消息的同步列表。按下按钮时,会将项目添加到列表中。线程将有一个无限循环,从列表中读取顶部项目(或睡眠直到其非空)并处理它(在这种情况下将其发送到服务器)。

更多相关文章

  1. Thrift项目Server端开发流程
  2. JSP页面中有一个按钮 点击之后执行JAVA文件
  3. [java混淆器问题] 如何让web项目的class文件不能被反编译,又能在w
  4. java socket项目打包成可运行的JAR包!!!!!
  5. 阿里云服务器上部署java项目(安装jdk,tomcat)
  6. JAVASCRIPT实现翻页保存已勾选的项目
  7. Blue Pelican Java项目“Masking Telemetry Data”;编译但没有运
  8. java项目中Classpath路径到底指的是哪里?
  9. Java项目中的classpath

随机推荐

  1. 如何在表单行SQL中检查是否有任何值为Nul
  2. 麻烦问下,为什么我的mysql存储过程一次调
  3. Ruby 1.9 + MySQL中发生访问错误
  4. MySql索引的优缺点
  5. [转]swoole安装报错详解 mysqlnd_find_ch
  6. 我需要介绍MongoDB / NoSQL数据库
  7. MySQL数据库辅助类
  8. Php数据库为GoJs格式化json
  9. MySql新建连接不能运行以及如何导入sql
  10. MySQL定时检查是否宕机并邮件通知