android - 点击button后开启分线程网络请求
伊谢尔伦
伊谢尔伦 2017-04-17 17:52:47
0
8
653

最近一个项目涉及到好多点击button进行开分线程网络请求,但是问题来了,如果button不做处理,用户不断的去点击button,就会有一堆线程创建,应用卡死,或者在没网络的时候也一直去点击button。有没有好的处理方法,求教!

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(8)
左手右手慢动作

You can set the time interval between two clicks. If it is less than a certain period of time, the second click will not respond

迷茫

1. First determine whether there is a network. If the network is unavailable, return directly
2. Filter repeated clicks
3. If you hope that new requests will not be triggered before the previous request is returned, you can set a status flag

黄舟

When the user clicks the button for the first time, a friendly prompt interface is given: such as diaolg, which prompts the user to wait for data to be returned.
Otherwise, in terms of user experience, there is no response when I click the button, and I will keep clicking.
Hope it helps you.

小葫芦
  1. Use thread pool to limit the maximum number of threads.

  2. You cannot initiate network requests for the same URL at the same time

  3. Caching

Volley can do all the above

大家讲道理

As mentioned above, a network framework must be used in this situation. Volley is indeed very suitable. I recommend the Volley source code analysis I wrote. I hope it will be helpful to you: https://github.com/wangzhengy...

巴扎黑

After initiating the request, the Click event of the Button is blocked and restored after the request is completed.

大家讲道理

After clicking the button, the button will be made non-clickable. If possible, the dialog being requested will pop up. After requesting the data, the dialog will be canceled and the button will be made clickable.

巴扎黑

Write a judgment. Set a flag, TAG = false; if (!TAG) {//execute}
When turned on, TAG = true;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!