泄漏了最初添加到此处的窗口

时间:2018-05-19 15:17:16

标签: android memory-leaks dialog

这是我的代码

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

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(DetailsActivity.this);
        pDialog.setMessage("Booking...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... arg) {
        int success;
        try {
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("gedung", gedung));
            params.add(new BasicNameValuePair("lantai", lantai));
            params.add(new BasicNameValuePair("nim", nim));
            params.add(new BasicNameValuePair("nama", nama));
            params.add(new BasicNameValuePair("jumlah peserta", peserta));
            params.add(new BasicNameValuePair("keperluan", keperluan));
            params.add(new BasicNameValuePair("ruang", ruang));
            Log.d("request!", "starting");
            JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "GET", params);
            // checking log for json response
            Log.d("proses membuat", json.toString());
            // success tag for json
            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("Berhasil membuat !", json.toString());
                return json.getString(TAG_MESSAGE);
            } else {
                return json.getString(TAG_MESSAGE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String message) {
        pDialog.dismiss();
        Toast.makeText(DetailsActivity.this, "Berhasil meminjam kelas", Toast.LENGTH_SHORT).show();
        Intent i = new Intent(DetailsActivity.this, MainActivity.class);
        startActivity(i);
    }
}

我不知道错误是什么意思。 我已经在我的对话框中调用了dismiss ,但它仍然无效。它显示了对话框,但在此之后强制关闭。我有错误是因为我试图发布的JSON还是什么?

这是我的logcat

E/WindowManager: android.view.WindowLeaked: Activity com.mqa.android.peminjamankelas.DetailsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{1a6f9473 V.E..... R......D 0,0-1026,304} that was originally added here
                 at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
                 at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
                 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
                 at android.app.Dialog.show(Dialog.java:298)
                 at com.mqa.android.peminjamankelas.DetailsActivity$BuatPeminjaman.onPreExecute(DetailsActivity.java:87)
                 at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:591)
                 at android.os.AsyncTask.execute(AsyncTask.java:539)
                 at com.mqa.android.peminjamankelas.DetailsActivity$1.onClick(DetailsActivity.java:73)
                 at android.view.View.performClick(View.java:4780)
                 at android.view.View$PerformClick.run(View.java:19866)
                 at android.os.Handler.handleCallback(Handler.java:739)
                 at android.os.Handler.dispatchMessage(Handler.java:95)
                 at android.os.Looper.loop(Looper.java:135)
                 at android.app.ActivityThread.main(ActivityThread.java:5254)
                 at java.lang.reflect.Method.invoke(Native Method)
                 at java.lang.reflect.Method.invoke(Method.java:372)
                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

请帮忙。或者,如果您有任何建议如何将数据发布到数据库而没有错误,那就没问题

1 个答案:

答案 0 :(得分:-1)

您退出活动后尝试显示对话框。

  

在退出之前,在您创建的Dialog实例上调用dismiss()   活动,例如在onPause()或onDestroy()

请参阅link