Manish Dwivedi
How to create alerts in android
By Manish Dwivedi in Android on Mar 29 2014
  • MD   REHAN FAISAl
    Sep, 2016 5

    Dear, If You want to create real time alert then GCM (Google Cloud Messaging ) is best for Alert and Notification on device.If you want to local alert like data pack off Alert then Alert dialog and Toast is the way by which you can alert the user

    • 1
  • Simran Kaur
    Jun, 2016 23

    Android Tutorial- http://www.hub4tech.com/android-tutorial

    • 1
  • Pankaj  Kumar Choudhary
    Aug, 2015 29

    http://stackoverflow.com/questions/12600360/how-to-make-an-alert-dialog-box-in-android

    • 1
  • Neeraj Kumar
    Jun, 2015 8

    http://stackoverflow.com/questions/26097513/android-simple-alert-dialog

    • 1
  • Munesh Sharma
    Apr, 2014 22

    http://stackoverflow.com/questions/12600360/how-to-make-an-alert-dialog-box-in-android

    • 1
  • Khan Abrar Ahmed
    Apr, 2014 6

    http://www.wikihow.com/Show-Alert-Dialog-in-Android

    • 1
  • Rohit Gupta
    Jul, 2019 15

    We need to use the AlertDialog package to create the Alert in Android

    the following program demonstartes how we can create a alert dialog box

    1. import android.content.DialogInterface;
    2. import android.support.v7.app.AlertDialog;
    3. import android.support.v7.app.AppCompatActivity;
    4. import android.os.Bundle;
    5. public class MainActivity extends AppCompatActivity {
    6. @Override
    7. protected void onCreate(Bundle savedInstanceState)
    8. {
    9. super.onCreate(savedInstanceState);
    10. setContentView(R.layout.activity_main);
    11. }
    12. // Declare the onBackPressed method
    13. // when the back button is pressed
    14. // this method will call
    15. @Override
    16. public void onBackPressed()
    17. {
    18. // Create the object of
    19. // AlertDialog Builder class
    20. AlertDialog.Builder builder
    21. = new AlertDialog
    22. .Builder(MainActivity.this);
    23. // Set the message show for the Alert time
    24. builder.setMessage("Do you want to exit ?");
    25. // Set Alert Title
    26. builder.setTitle("Alert !");
    27. // Set Cancelable false
    28. // for when the user clicks on the outside
    29. // the Dialog Box then it will remain show
    30. builder.setCancelable(false);
    31. // Set the positive button with yes name
    32. // OnClickListener method is use of
    33. // DialogInterface interface.
    34. builder
    35. .setPositiveButton(
    36. "Yes",
    37. new DialogInterface
    38. .OnClickListener() {
    39. @Override
    40. public void onClick(DialogInterface dialog,
    41. int which)
    42. {
    43. // When the user click yes button
    44. // then app will close
    45. finish();
    46. }
    47. });
    48. // Set the Negative button with No name
    49. // OnClickListener method is use
    50. // of DialogInterface interface.
    51. builder
    52. .setNegativeButton(
    53. "No",
    54. new DialogInterface
    55. .OnClickListener() {
    56. @Override
    57. public void onClick(DialogInterface dialog,
    58. int which)
    59. {
    60. // If user click no
    61. // then dialog box is canceled.
    62. dialog.cancel();
    63. }
    64. });
    65. // Create the Alert dialog
    66. AlertDialog alertDialog = builder.create();
    67. // Show the Alert Dialog box
    68. alertDialog.show();
    69. }
    70. }

    the above program will generte the an alert when we try to exit the app

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS