android - How to handle the flow when a Network Exception is thrown -
i built app , need handle network exceptions in many places. want know way it.
in activity
have like:
oncreate { ... fetchdata(); // needs internet processdata(); showdata(); }
in fetchdata()
method, might not fetch because there's no connectivity or poor signal. in case, show alertdialog
, tell user there network issue, , when clicks ok
try fetch again.
the problem thread run fetchdata()
, build , show dialog
, keep running processdata()
, on. method fetchdata()
called 2 different places in app, ideal stop thread until tries again , load data. logic can use here?
i know might simple question, i'm stuck on , don't know patterns apply. should propagate error , handle in calls fetchdata()
, or there way stop thread until data loaded?
edit: fetchdata()
is working , runs background thread downloads data, , wait finish return response or null. far, if there's error null , logs me network error. want know how handle , keep flow
just modify code this:
oncreate { ... asynctask task = new asynctask() { @override protected object doinbackground(object[] objects) { try{ fetchdata();} catch(exception e) {e.printstacktrace();} } } processdata(); showdata(); }
Comments
Post a Comment