Android Programming: Http Get Request Not Working
I require a GET reequest from my own server to be extracted from the web and then displayed on screen with a TextView. I have set up a GET Request. public class GetMethodEx { pub
Solution 1:
Change your code using AsyncTask if you want to make any network operation from Ui Thread as:
publicclassHomeextendsActivity {
TextView httpStuff;
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.httpexample);
httpStuff = (TextView) findViewById(R.id.tvhttp);
newLongOperation().execute("");
}
privateclassLongOperationextendsAsyncTask<String, Void, String> {
@OverrideprotectedStringdoInBackground(String... params) {
GetMethodEx test = newGetMethodEx();
String returned;
try {
returned = test.getInternetData();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returned;
}
@OverrideprotectedvoidonPostExecute(String result) {
// Update Ui here
httpStuff.setText(result);
}
}
}
Solution 2:
Android OS > = 3.0
does not allow NetworkRequest
on main UI thread.
Use AsyncTask to call webrequest.
Post a Comment for "Android Programming: Http Get Request Not Working"