【问题标题】:Android app rating dialog wont closeAndroid 应用评分对话框不会关闭
【发布时间】:2013-06-10 09:35:18
【问题描述】:

我正在开发一款应用,要求用户在 Play 商店中对其进行评分。它运作良好。如果用户按下“Rate”按钮,则会进入应用程序的 Play 商店页面。如果你按下后退按钮,我的应用程序会在前面显示评级对话框。我在启动 Play Store 意图之前或之后使用了dialog.dismiss(),但对话框不会关闭,它会一直留在那里。

这是我的代码,请帮助我!

  private void rateDialog() {

        AlertDialog.Builder mDialogBuilder;

        mDialogBuilder = new AlertDialog.Builder(MainActivity.this);
        mDialogBuilder.setCancelable(true);
        mDialogBuilder.setTitle(getString(R.string.title_RateDialog));

        if (!appdata.getBoolean(Constants.IS_RATE_IGNORED, false) && (appdata.getInt(Constants.START_COUNT, 1) % 4) == 0) {
            mDialogBuilder.setMessage(getString(R.string.text_RateDialogMessage));
            mDialogBuilder.setPositiveButton(R.string.text_OK,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            appdataEditor.putBoolean(Constants.IS_RATE_IGNORED, true);
                            dialog.dismiss();
                            try{
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.PLAY_STORE_URL)));
                            } catch (ActivityNotFoundException e){
                                Toast.makeText(getApplicationContext(), "Could not open market page.", Toast.LENGTH_LONG).show();
                            }
                        }
                    });
            mDialogBuilder.setNeutralButton(getString(R.string.text_NotNow),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }
                    });
            mDialogBuilder.setNegativeButton(getString(R.string.text_Never),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int id) {
                            appdataEditor.putBoolean(Constants.IS_RATE_IGNORED, true);
                        }
                    });

            AlertDialog rateDialog = mDialogBuilder.create();
            rateDialog.show();
        }
    }

我在 onStart() 方法中调用它。

【问题讨论】:

    标签: android dialog android-alertdialog dismiss rate


    【解决方案1】:

    你忘记在appdataEditor 上调用commit() => appdataEditor.commit() 在输入布尔值之后。

    还请记住,由于活动生命周期,一旦活动回到前台,将再次调用 OnStart(),因此再次调用 rateDialog(),如果这是您的设计,则忽略这部分..

    【讨论】:

    • 是的,这就是问题所在。现在可以正常工作了。 :) 谢谢!
    【解决方案2】:

    这是因为您在 onStart() 中调用它。

    【讨论】:

      猜你喜欢
      • 2010-10-27
      • 2022-11-03
      • 2012-09-20
      • 1970-01-01
      • 2014-10-21
      • 2013-07-05
      • 2011-11-28
      • 1970-01-01
      相关资源
      最近更新 更多