在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