gpt4 book ai didi

android - MySQL插入数据后窗口泄漏错误未解决

转载 作者:行者123 更新时间:2023-11-29 17:54:42 25 4
gpt4 key购买 nike

我在我的项目中使用 localhost 和 MySQL 数据库。我必须将数据插入数据库,然后转到下一个预期 Activity 。数据已成功添加到数据库中,但应用程序终止后,logcat 中出现窗口泄漏错误。

代码:

class CreateNewCourier extends AsyncTask<String, String, String> {

/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(PackageDetail.this);
pDialog.setMessage("Adding Details..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

/**
* Creating product
* */
protected String doInBackground(String... args) {


// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_no", "120"));
params.add(new BasicNameValuePair("recp_name", recp_name));
params.add(new BasicNameValuePair("recp_no", recp_no));
params.add(new BasicNameValuePair("recp_adres", recp_adres));
params.add(new BasicNameValuePair("pkg_name", pkg_name));
params.add(new BasicNameValuePair("pkg_quan", pkg_quan));
params.add(new BasicNameValuePair("pickup_adres", pickup_adres));
params.add(new BasicNameValuePair("pkg_type", pkg_type));
params.add(new BasicNameValuePair("veh_type", veh_type));
params.add(new BasicNameValuePair("Breakable", Breakable));

// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params);

// check log cat fro response
Log.d("Create Response", json.toString());

// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);

if (success == 1) {
// successfully created product
Intent i = new Intent(getApplicationContext(), Login.class);
startActivity(i);

// closing this screen

finish();
} else {

//failed to create product
}
} catch (JSONException e) {
e.printStackTrace();

}

return null;
}

/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
//dismiss the dialog once done
pDialog.dismiss();

}

Here is my logcat

最佳答案

这是解决方案,将此代码移至 pDialog.dismiss();

之后的 onPostExecute()
if (success == 1) {
// successfully created product
Intent i = new Intent(getApplicationContext(), Login.class);
startActivity(i);

// closing this screen

finish();
} else {

//failed to create product
}

并且还在 Activity 的 onDestroy 中添加 pDialog.dismiss(); 以避免泄漏

关于android - MySQL插入数据后窗口泄漏错误未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48962101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com