如何每10次启动显示警报对话框?

Vla*_*mir 0 java android

我不知道这个问题是否被提出,但我找不到.我希望警报对话框显示每10次或更多次应用程序启动.

 AlertDialog.Builder a_builder = new AlertDialog.Builder(MainActivity.this);
 a_builder.setMessage("Please take time and rate our application")
 .setCancelable(false)
 .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
                    Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
                    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

                    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                            Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                            Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    try {
                        startActivity(goToMarket);
                    } catch (ActivityNotFoundException e) {
                        startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName())));
                    }

                }
            }).setNegativeButton("Not Now",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }) ;
    AlertDialog alert = a_builder.create();
    alert.setTitle("Rate Us !");
    alert.show();
Run Code Online (Sandbox Code Playgroud)

Man*_*ath 5

设置sharedPreferences并每次按存储在其中的值递增计数.当值达到计数时,只显示警报并重置共享偏好.