I am using MySQL database to get students info. I followed a tutorial and Android leaked window shows up. Here is the code for calling the async task and get the data from the database.
class getallstudents extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SecondActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jparser.makeHttpRequest("http://127.0.0.1/testphp/get_all_students.php", "GET", params);
try {
String st_id = json.getString(Tag_st_id);
String st_name = json.getString(Tag_st_name);
String st_phone = json.getString(Tag_st_phone);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
TextView tv2 = (TextView) findViewById(R.id.textView2);
tv2.setText(Tag_st_id);
TextView tv3 = (TextView) findViewById(R.id.textView3);
tv3.setText(Tag_st_name);
TextView tv4 = (TextView) findViewById(R.id.textView4);
tv4.setText(Tag_st_phone);
}
});
}
}
}