How to make term and condition activity in an Android application in Android Studio

10,033

Show it in AlertDialog and put the result (Accept or Decline) at the SharedPreferences as boolean value. Then just check key value every time you start your app.

final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean agreed = sharedPreferences.getBoolean("agreed",false);
if (!agreed) {
    new AlertDialog.Builder(context)
        .setTitle("License agreement")
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Editor editor = sharedPreferences.edit();
                editor.putBoolean("agreed", true);
                editor.commit();
            }
        })
        .setNegativeButton("No", null)
        .setMessage(text)
        .show();
}
Share:
10,033

Related videos on Youtube

Nigam Patro
Author by

Nigam Patro

Updated on September 15, 2022

Comments

  • Nigam Patro
    Nigam Patro over 1 year

    I have developed an application and I want to make my 1st page like a terms and conditions activity in which the activity shows only first time after installing. And then if the user accepts it never shows on that device again. If the user rejects the terms and conditions activity it will be showing every time the application starts.

    My question is "how can I implement the code?"