简体   繁体   English

按下按钮后延迟

[英]Delay after pressing a button

After I press a button, Android parse a JSON file and pick the info it needs. 按下按钮后,Android会解析JSON文件并选择所需的信息。 Until yesterday, I was using an external library created by a user and it worked perfectly. 直到昨天,我正在使用由用户创建的外部库,它工作得很好。 But now, I don't want to depend on him, so I've searching info about Google's GSON. 但现在,我不想依赖他,所以我一直在搜索谷歌的GSON信息。 I've implemented this library with no problem, but now, after pressing the button that opens a new activity there's a delay. 我已经实现了这个库没有问题,但是现在,按下打开新活动的按钮后会有延迟。

This delay is due to the connection and parsing that are done before the activity shows. 此延迟是由于在活动显示之前完成的连接和解析。

How can I force the app to wait the Internet connection until de Activity is shown? 如何强制应用程序等待Internet连接,直到显示de Activity? It's a lil bit uncomfortable because after pressing the button, it seems that the app has frozen, but after all data is loaded, the new activity appears. 这有点不舒服,因为在按下按钮后,应用程序似乎已冻结,但在加载所有数据后,将显示新活动。

Thank you in advance! 先感谢您!

Use AsyncTask or Handler for network operations. 使用AsyncTask或Handler进行网络操作。 Do never put "long time" operations into the UI thread 永远不要将“长时间”操作放入UI线程中

使用asyncTask ..如果服务器通信成功,则显示新的Activity或者退出..

它是可能的,通过Handler和AsyncTask看到这个如何在Android onClick函数中设置延迟你会得到如何使用Handler并看到这个为Asynctask https://stackoverflow.com/questions/7644567/need-a-simple-example -用于-Android的的AsyncTask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM