The invention relates to a method for displaying network information, which comprises the following steps: first, to generate a successor to the Handler, HttpHandler, onSuccess, onError, onRetry in the interface; step two, create a thread and start, the network access operation in HttpClient.execute within the thread (step three), the network access; the results by HttpHandler.onSuccess (HttpHandler.onError) or (HttpHandler.onRetry) or () to the main thread, the thread comprises a timeout error information, and refresh the interface in the main thread, pop-up information.
【技术实现步骤摘要】
本专利技术涉及一种Android系统下,获取网络数据并直接显示在主线程上的方法。
技术介绍
移动互联网的快速发展是当今科技领域不可忽视的潮流,其给用户带来了全新的体验,在满足广大用户的需求上扮演着越来越重要的角色。而随着Android系统在互联网运用中越来越广泛,那么如何从服务端上高效率的获取资源信息进行开发,并且保证良好的软件结构,就成了Android研发中的一个关键。
技术实现思路
本专利技术的目的在于提供一种不影响主线程操作,并能在网络较差的情况下获取网络数据,并直接显示在主线程界面上的显示网络信息的方法。为实现上述目的,本专利技术提供如下技术方案:显示网络信息的方法,其包括以下步骤:步骤一、继承Handler,生成一个HttpHandler,内有onSuccess、onError、onRetry接口;步骤二、创建一个线程并start,在该线程内进行网络获取操作HttpClient.execute();步骤三、把网络获取到的结果,通过HttpHandler.onSuccess()或HttpHandler.onError()或HttpHandler.onRetry()传给主线程,结果包括线程超时错误信息,并在主线程上刷新界面,弹出信息。进一步的方案是,利用子线程来获取网络信息以不影响主线程的操作。进一步的方案是,将网络反馈的结果直接通过Handler反馈到主线程,以便用户显示或错误提示。更进一步的方案是,利用HttpClient.execute时提供的id,用户在onSuccess或onError内先根据id去判断是否所需要网络应答。与现有技术相比,本专 ...
【技术保护点】
显示网络信息的方法,其特征是包括以下步骤:步骤一、继承Handler,生成一个HttpHandler,内有onSuccess、onError、onRetry接口;步骤二、创建一个线程并start,在该线程内进行网络获取操作HttpClient.execute();步骤三、把网络获取到的结果,通过HttpHandler.onSuccess()或HttpHandler.onError()或HttpHandler.onRetry()传给主线程,结果包括线程超时错误信息,并在主线程上刷新界面,弹出信息。
【技术特征摘要】
1.显示网络信息的方法,其特征是包括以下步骤:步骤一、继承Handler,生成一个HttpHandler,内有onSuccess、onError、onRetry接口;步骤二、创建一个线程并start,在该线程内进行网络获取操作HttpClient.execute();步骤三、把网络获取到的结果,通过HttpHandler.onSuccess()或HttpHandler.onError()或HttpHandler.onRetry()传给主线程,结果包括线程超...
【专利技术属性】
技术研发人员:吴斌斌,田红玉,刘鹏程,
申请(专利权)人:数源科技股份有限公司,
类型:发明
国别省市:浙江;33
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。