Question

I'm developing an app that ask the user for rating it in the Play Store. It works well. If the user presses the Rate button it leads to the Play Store page for the app. Than if you press the Back button, my app goes in front showing the rating dialog. I used dialog.dismiss() just before or after starting the Play Store intent, but the dialog wont dismiss, it stays there.

Here's my code, please help me!

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

I call this in the onStart() method.

Was it helpful?

Solution

You forgot to call commit() on appdataEditor => appdataEditor.commit() after putting the boolean.

Also keep in mind that due to the activity life-cycle, the OnStart() is being called again once the activity comes back into the foreground and therefore calling rateDialog() again, if that is your design, then ignore this part..

OTHER TIPS

This is happening because you are calling it in onStart().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top