Reputation: 5879
In my app i connect to a server, which responds with an xml. I parse it with the SAX Parser, and get the data.
The question is:
What is the best way to handle connection issues?
(At this moment if there is no internet connection available the app simply continues showing the ProgressDialog
i implemented)
Upvotes: 4
Views: 1245
Reputation: 10908
As well as following the suggestion of Heiko Rupp, you can also check for the availability of a network connection prior to performing your download. See my post on the subject.
Upvotes: 0
Reputation: 30944
So you basically do (Pseudo code)
ProgessDialog pd = new ProgressDialog(this).show();
Sax.parseStuff();
pd.dismiss();
In this case, wrap the parsing stuff and cancel the dialog on Exception
ProgessDialog pd = new ProgressDialog(this).show();
try {
Sax.parseStuff();
}
finally {
pd.dismiss(); // or cancel
}
You can also do a try { .. } catch (XYZException e ; pd.cancel(); throw e)
if you want to process the Exception in a different layer of your app.
Upvotes: 4