Here is my java android code which should pass 'Preferred hotels' string to a php file and later read what have been passed.
sendSubMenuDetail("Preferred hotels");
This is evoked at the activity load. Whose function is below:
public void sendSubMenuDetail(String suggestion){
String urlSuffix = "?suggestion="+suggestion;
class RegisterUser extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(ActivitySubMenu.this, "Please Wait",null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getBaseContext(),s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(address+s);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String result;
result = bufferedReader.readLine();
return result;
}catch(Exception e){
return null;
}
}
}
RegisterUser ru = new RegisterUser();
ru.execute(urlSuffix);
}
The output dislayed in a toast here is 'Preferred' instead of 'Preferred hotels'. I tried figuring out what the problem might be with no success.