Sunday, February 23, 2014

 Android developers how to deal with network anomaly?


There is a class of data processing request various networks, there are a number of activity which calls a method of the class to request data
I have an idea, that is, when each call network approach, both prior to check whether the network is available. However, this may affect the efficiency
Second: The network connection timed out how to deal with? There is nothing like that kind of unified web portal to handle exceptions such as struts2 global exception.
It is said that in that class of the request on the network connection timeout exception handling, but android is asynchronous data acquisition. I do not have to judge the abnormal activity types (whether the connection timeout, connection timeout to prompt the user, because there may be no data is returned instead of a connection timeout, so the situation is different in different prompts.)

I do not know what a good mind.
Check whether the network should be available somewhere check? ? ?
Connection timed out how to deal with?
Give code too thanks!<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Check the network should be in every method I need to call the network to check. This should be no problem.
Connection timeout to throw exceptions chant, after capturing ui displayed as a error dialog.
Asynchronous send timeout exception handler can be used, if you can catch exceptions with AsyncTask in onCancelled written inside your timeout logic.

Timeout can be used to determine the current time plus the connection settings, more than throw a timeout exception.
Reply:
cited a floor wlcw16 reply:
check the network should be to check in every time you need to call the network method. This should be no problem.
Connection timeout to throw exceptions chant, after capturing ui displayed as a error dialog.
Asynchronous send timeout exception handler can be used, if you can catch exceptions with AsyncTask in onCancelled written inside your timeout logic.

Timeout can be used to determine the current time plus the connection settings, more than throw a timeout exception.

Thank you for your thoughts: I realize this is a preliminary test should be feasible:
Application checks the network has started, if there is no network to call the system set up the network, the user can not set my application to proceed,
But I do not check the network, and directly connected to the network using httpClient, set the timeout, then catch the exception, when an exception is caught after returning to the caller with a null. The caller then it is AsyncTask onPostExecute method that determines if the return value is null, then go to a unified Activity to display a screen that tells users to network anomalies.
Doing just that, and now I have a lot of activity, each activity must be to judge the return value, though a bit tedious, but it seems to still be in effect. I do not know what a good way it
Oh, here I ask one more question, I capture (custom) to a network anomaly after
if I catch the throw new exceptionWhy an exception occurs when the program will pop up force close box (that is android system crash box) If I do not do anything just to capture, to not pop this box, the program can be executed properly to my unusual page go? !
Reply:
You pop unusual problem, I guess your network requests to do it in the thread, thread can not directly manipulate UI, must send a message to the handler, told the UI thread, there is a UI to be updated to the UI thread to handle
Reply:
Plus a looper in the thread
Reply:
reference to the second floor anybyb reply:
Quote: references to a floor wlcw16 reply:

Check the network should be in every method I need to call the network to check. This should be no problem.
Connection timeout to throw exceptions chant, after capturing ui displayed as a error dialog.
Asynchronous send timeout exception handler can be used, if you can catch exceptions with AsyncTask in onCancelled written inside your timeout logic.

Timeout can be used to determine the current time plus the connection settings, more than throw a timeout exception.

Thank you for your thoughts: I realize this is a preliminary test should be feasible:
Application checks the network has started, if there is no network to call the system set up the network, the user can not set my application to proceed,
But I do not check the network, and directly connected to the network using httpClient, set the timeout, then catch the exception, when an exception is caught after returning to the caller with a null. The caller then it is AsyncTask onPostExecute method that determines if the return value is null, then go to a unified Activity to display a screen that tells users to network anomalies.
Doing just that, and now I have a lot of activity, each activity must be to judge the return value, though a bit tedious, but it seems to still be in effect. I do not know what a good way it
Oh, here I ask one more question, I capture (custom) to a network anomaly after
if I catch the throw new exceptionWhy an exception occurs when the program will pop up force close box (that is android system crash box) If I do not do anything just to capture, to not pop this box, the program can be executed properly to my unusual page go? !

Exceptions thrown the child thread the main thread can not be caught. .

No comments:

Post a Comment