android - How to intent From Catch Block if exception is occurs -


i trying intent catch block if exception occurs.it not intent. when have enter wrong ip gives "malformedurlexception" purpose need change ip address activity please me.

the log file: this image of log file

the code:

protected class asynclogin extends asynctask<string, jsonobject, boolean> {          string username = null;          @override         protected boolean doinbackground(string... params) {              restapi api = new restapi();             boolean userauth = false;              try {                  // call user authentication method in api                 jsonobject jsonobj = api.userauthentications(params[0],                         params[1]);                  jsonparser parser = new jsonparser();                 userauth = parser.parseuserauth(jsonobj);                 username = params[0];                  //parse json object boolean               } catch (exception e) {                 // todo auto-generated catch block                 intent openstartingpoint = new intent(getapplicationcontext(), alertforip.class);                 openstartingpoint.putextra("forcheck", "yes");                 startactivity(openstartingpoint);                 log.d("asynclogin", e.getmessage());             }              return userauth;         }          @override         protected void onpreexecute() {              super.onpreexecute();           }          @override         protected void onpostexecute(boolean result) {             // todo auto-generated method stub              //check user validity             if (result) {                 intent = new intent(sample.this,                         mainactivity.class);                 i.putextra("forbutton", cnt);                 i.putextra("uname", username);                 startactivity(i);             } else {                 toast.maketext(context, "not valid username/password , re-enter ip", toast.length_short).show();                 intent = new intent(sample.this, alertforip.class);                 i.putextra("forcheck", "yes");                 startactivity(i);               }          }      }  

i think exception should related url being called in api.userauthentications(params[0], params[1]);

as of firing of intent, follow different approach. in doinbackground, upon exception, pass "error" status result onpostexecute().

and in onpostexecute, return error status calling activity.

and have calling activity, in ui thread, start new activity.

for quick test replace

} catch (exception e) {                 // todo auto-generated catch block                 intent openstartingpoint = new intent(getapplicationcontext(), alertforip.class);                 openstartingpoint.putextra("forcheck", "yes");                 startactivity(openstartingpoint);                 log.d("asynclogin", e.getmessage());             } 

with

 } catch (exception e) {      // todo auto-generated catch block       log.d("asynclogin", e.getmessage());      return false;  } 

by returning false, onpostexecute() receive false result parameter. , acording "if" same doing in catch clause of doinbackground.

the difference onpostexecute runs on ui thread , doinbackground doesn't.

if works, can work on part of returning error condition calling activity in onpostexecute.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -