Android漏掉了活动

时间:2015-02-28 12:35:33

标签: php android mysqli

我正在使用MySQL数据库来获取学生信息。我按照教程和Android泄露的窗口显示。以下是调用异步任务并从数据库中获取数据的代码。

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);
                        }
                });

            }
}
}

0 个答案:

没有答案