Here's how I implemented the Dialog according to Cristian's example:
In the activity class, I created this method:
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: ... ")
.setCancelable(false)
.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!
editor.commit();
}
})
.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
nm.cancel(R.notification.running); // cancel the NotificationManager (icon)
System.exit(0);
}
});
AlertDialog alert = builder.create();
return alert;
}
At the beginning of the onCreate() method, I added these lines:
// Check whether the user has already accepted
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean accepted = settings.getBoolean("accepted", false);
if( accepted ){
// do what ever you want... for instance:
}else{
showDialog(0);
}
Cheers,
Chris