It sounds like you are either not writing or not using your AsyncTask
correctly. This is my version that should do what you are attempting. I follow up with how to call this. There are a few common mistakes, such as directly calling the doInBackground
method instead of execute
, so this should clear anything up.
To wrap this code in an AsyncTask
, create the following class
:
public class MyJSONRequest extends AsyncTask<Void, Void, Void> {
String url;
String method;
List<NameValuePair> params;
public MyJSONRequest(String url, String method, List<NameValuePair> params) {
this.url = url;
this.method = method;
this.params = params;
}
@Override
public Void doInBackground(Void...) {
makeHttpRequest(url, method, params)
}
}
Now, to complete the task with no errors, do:
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("noteid", "1"));
new MyJSONRequest("http://android-connection.cba.pl/get_note.php", "GET", list).execute();
Also, you should note that if(method == "POST")
and if(method == "POST")
will not resolve how you are expecting. You need to change these to if(method.equals("POST"))
and if(method.equals("GET"))
.