警报对话框上的窗口装饰泄漏

时间:2019-05-16 08:37:04

标签: android alertdialog android-alertdialog

我是新手,可以了解这种类型的错误。我不明白这一点。我在更改活动之前关闭了所有功能,但是仍然面临着同样的问题。 这是我的代码。而且我无法解决此错误。

         private void versionChecker() {
        VersionChecker versionChecker = new VersionChecker(SplashActivity.this);

        try {
            latestVersion = versionChecker.execute().get();
            Log.d(TAG, "latestVersion: " + latestVersion);
//            Toast.makeText(getBaseContext(), latestVersion, Toast.LENGTH_SHORT).show();

        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

        if (latestVersion != null) {
//            Toast.makeText(this, "not null", Toast.LENGTH_SHORT).show();

            Log.d(TAG, "latest:  " + version);
            Log.d(TAG, "latestVersion: " + latestVersion);
            if (version.equals(latestVersion)) {
                startWithDelay();

            } else {
                ViewGroup viewGroup = findViewById(android.R.id.content);
                View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_custom, viewGroup, false);
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setCancelable(false);

                builder.setPositiveButton("Allow", (dialog, which) -> {
                    dialog.dismiss();
//                    startActivity(new Intent(Intent.ACTION_VIEW,
//                            Uri.parse("https://play.google.com/store/apps/details?id="
//                                    + BuildConfig.APPLICATION_ID)));
//                    finish();

                });

                builder.setNegativeButton("Deny",(dialog, which) -> {
                    if (alertDialog != null && alertDialog.isShowing()) {
                        alertDialog.dismiss();
                    }
                    startWithDelay();

                });




                        builder.setView(dialogView);
                        alertDialog = builder.create();
                        alertDialog.show();


            }


        } else {
//            try {
//                Log.d(TAG, "url:" + urlObject);
//                Intent i = new Intent("android.intent.action.MAIN");
//                i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
//                i.addCategory("android.intent.category.LAUNCHER");
//                i.setData(Uri.parse(urlObject));
//                startActivity(i);
//            } catch (ActivityNotFoundException e) {
//                // Chrome is not installed
//                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlObject));
//                startActivity(i);
//            }
                     Toast.makeText(this, "to do for url coding", Toast.LENGTH_SHORT).show();

//            startWithDelay();
        }

    }

    private void startWithDelay() {
//        new Handler().postDelayed(() -> {
        if (signnedIn.equals("true")  &&  loggedIn.equals("true")){

            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();

        }else {

            startActivity(new Intent(SplashActivity.this, FirstActivity.class));
            finish();
        }

//        },3000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (alertDialog != null){
            alertDialog.dismiss();
        }
    }


    @Override
    protected void onPause() {
        super.onPause();

        if (alertDialog != null){
            alertDialog.dismiss();
        }
    }

错误

E/WindowManager: android.view.WindowLeaked: Activity com.atomsgroup.firstaim.Activity.SplashActivity has leaked window DecorView@a9f6556[SplashActivity] that was originally added here

我尝试了 Link 1 Link 2等。

在这里我添加了有关在销毁和暂停时关闭的警报对话框,但Logcat显示了相同的错误。堆栈溢出对此类型的错误有很多疑问,但是我仍然找不到我的错误。

更新 这是我的版本Cheker Class

    public class VersionChecker extends AsyncTask <String, String, String> {


    private String newVersion;
    private Context context;

    public VersionChecker(Context context) {
        this.context = context;
    }

    @Override
    protected String doInBackground(String... params) {

        try {
            Log.d("resDoc", String.valueOf(BuildConfig.APPLICATION_ID));
//            BuildConfig.APPLICATION_ID + "&hl=en"
            Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID + "&hl=en")
                    .timeout(5000)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer("http://www.google.com")
                    .get();


            if (document != null) {
                Elements element = document.getElementsContainingOwnText("Current Version");
                for (Element ele : element) {
                    if (ele.siblingElements() != null) {
                        Elements sibElemets = ele.siblingElements();
                        for (Element sibElemet : sibElemets) {
                            newVersion = sibElemet.text();
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return newVersion;
    }
}

0 个答案:

没有答案
相关问题