https://techaxioms.com/add-android-exit-dialog-rating-option-android-app/
In this tutorial we are going to implement an exit dialog box for our android application. When user clicks back button on applications main activity then exit dialog box is invoked and displayed
with a custom message and 2 buttons “Rate us” and “Quit”.
Example Screen shot
Here is the code snippet
- public class MainHomeActivity extends AppCompatActivity
- {
- AlertDialog.Builder builder;
- protected void onCreate(Bundle savedInstanceState)
- {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.mainpage);
- }
- @Override
- public void onBackPressed()
- {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
- builder = new AlertDialog.Builder(MainHomeActivity.this);
- }
- else
- {
- builder = new AlertDialog.Builder(MainHomeActivity.this, AlertDialog.BUTTON_NEUTRAL);
- }
- builder.setTitle("Thank You");
- builder.setMessage("Thank You For Using Our Application Please Give Us Your Suggestions and Feedback ");
- builder.setNegativeButton("RATE US",
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog,
- int which)
- {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=ADD YOUR APPS PACKAGE NAME")); // Add package name of your application
- startActivity(intent);
- Toast.makeText(MainHomeActivity.this, "Thank you for your Rating",
- Toast.LENGTH_SHORT).show();
- }
- });
- builder.setPositiveButton("QUIT",
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog,
- int which)
- {
- finish();
- }
- });
- builder.show();
- }
- }
Comments
Post a Comment