I am a newbie to android development so please be patient with me.
I am trying to post user id and password to a PHP page and return data (page working fine, tested and returns Json data).
I followed online guides and had similar problem to:
How to send data to a website using httpPost, app crashes
So I followed what was said in the following Answer within the above post https://stackoverflow.com/a/18588948/3415061
No more Errors , but now how do I control what happens after data returned and if valid how do I go to the next screen and display it?
The following function executes the request but how I do I get the response to the screen if valid or not.
@Override
protected Boolean doInBackground(Void... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.blag.com/blag.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("acc", "blag"));
nameValuePairs.add(new BasicNameValuePair("usr", "blag"));
nameValuePairs.add(new BasicNameValuePair("pass", "blag"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
return true;
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false ;
}
Or am I suppose to access the response in here, but I tried to launch another screen from here but I got errors.
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if(result){
//successful request
}else{
//error in request response
}
// msgTextField.setText(""); // clear text box
}
Am I taking the correct approach to doing this?
Thanks in advance!!!
new code:
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(result=="HEllO"){
//successful request
Intent dashboard = new Intent(getApplicationContext(), MainOrder.class);
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(dashboard);
//userFunction.logoutUser(getActivity().getApplicationContext());
}else{
//error in request response
}
// msgTextField.setText(""); // clear text box
}
error on GetApplicationContext: The method getApplicationContext() is undefined for the type NetRequestAsync
and error on line Command StartActivity The method startActivity(Intent) is undefined for the type NetRequestAsync