Android: Show a legal agreement dialog before Program launches

person Jason Huangfolder_openAndroid, Javalocal_offer, , , , access_time January 17, 2011

You can easily show a legal liability agreement on the screen when the user first run your app.

The following code will show a legal notice and a “Agree”, No selection before launching the main app activity.

In the main activity’s OnCreate event, just call the showDialog(0). That would called the override onCreateDialog event defined below.

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

  protected Dialog onCreateDialog(int id){
    	// show disclaimer....
        // for example, you can show a dialog box... 
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("LEGAL DISCLAIMER: ... ")
               .setPositiveButton("Agree", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // and, if the user accept, you can execute something like this:
                       // We need an Editor object to make preference changes.
                       // All objects are from android.context.Context
                       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                       SharedPreferences.Editor editor = settings.edit();
                       editor.putBoolean("accepted", true);
                       // Commit the edits!
               .setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       //nm.cancel(R.notification.running); // cancel the NotificationManager (icon)
        AlertDialog alert = builder.create();
        return alert;


  1. Pingback: A very clean way to add a disclaimer/EULA to your Android application « Derek Reynolds – Brain Dump-O-Matic

  2. i used this in my two free android apps. it works great! thanks so much!!

  3. Akshat Rastogi

    what is PREFS_NAME. Please declare it in the code i am getting an error over there please reply soon

warningComments are closed.