68167

show a license agreement in android application

We have to show a license agreement dialog when user use the application at the first time, now I have two questions about this:

1 Where to put this dialog?

Add another activity or put the dialog just at the MainActivity which is the launch acitivty?

2 How to close the app if user hit "Reject"

Once user hit the "Reject" button which means that he/she does not agree our license, then we have to exit the application completely. How to make it?

<hr>

According to the answer of "Ahmad", I will decide to open a dialog or not at the beginning of the activity(the onCreate method):

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); this.setupLicense(); this.setupViews(); this.initSomeJob(); } private void setupLicense() { SharedPreferences setting = getSharedPreferences(IConstant.Map_License, 0); boolean mapLicenseAccept = setting.getBoolean(IConstant.Map_License, false); if (!mapLicenseAccept) { //user does not accept the license yet, we will open the dialog showDialog(Dialog_Map_License); } } @Override protected Dialog onCreateDialog(int id) { AlertDialog.Builder builder = new AlertDialog.Builder(this); switch (id) { case Dialog_Map_License: builder.setIconAttribute(android.R.attr.alertDialogIcon) .setTitle(R.string.map_license_title) .setMessage(R.string.map_license_content) .setPositiveButton(R.string.map_license_accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //License accepted, persisted it. SharedPreferences settings = getSharedPreferences(IConstant.Map_License, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(IConstant.Map_License, true); editor.commit(); } }) .setNegativeButton(R.string.map_license_reject, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //do nothing and exit Process.killProcess(Process.myPid()); System.exit(0); } }); Dialog target = builder.create(); target.setCanceledOnTouchOutside(false); return target; } return null; }

But now I have meet two problem:

1 Event I choose the "Accept" button, once I open my app the second time, the dialog will show.

It seems that the following code does not work:

editor.putBoolean(IConstant.Map_License, true); editor.commit();

2 When I show the dialog, the code:

this.setupViews(); this.initSomeJob();

will still run , they are not blocked which is out of expected, since nothing should be done before user hit the "Accept" button.

Any idea to fix it?

Answer1:

onCreateDialog has been deprecated. Use dialog fragment instead. The advantage will be that the code for displaying dialog will be moved from activity and you can then display dialog from any activity. Also move

SharedPreferences setting = getSharedPreferences(IConstant.Map_License, 0); boolean mapLicenseAccept = setting.getBoolean(IConstant.Map_License, false);

to a utility method like isLicenceAccepted and similarly for storing the data

SharedPreferences settings = getSharedPreferences(IConstant.Map_License, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(IConstant.Map_License, true); editor.commit();

to method like acceptLicence in utility. You can find how to make communication between dialog Fragment and your activity here. In your interface instead of onArticleSelected you will have to implement two methods onLicence accepted and onLicenceRejected. Implement the interface in you activity override these two methods and take appropriate action.

Answer2:

Where to put this dialog?

Right at the beginning, when the user opens the app for the first time. Keep track of that by saving it in your shared preferences, if this dialog has been already shown or not. You don't have to create a separate activity for this. You could, but most apps I've seen out there don't.

How to close the app if user hit "Reject"

Just finish the Activity and also save that in your shared preferences as well. So every time the user opens your app you check weather the boolean value for "hasUserAcceptedOurAgreement" is true or not and proceed depending on that.

<hr>

I'm only answering from a technical standpoint on how this could be done reliably. I'm not a lawyer, but as far as I know, it's perfectly valid to just submit your license agreement to the play store, so it's available from the applications application page (Why else would there be this option?).

Recommend

  • Handling custom attributes
  • How do I set the default date in a DatePickerDialog in my fragment from the host activity?
  • MySQL 3.23 UNION fails with Error 1064 [closed]
  • Hierarchical Time Series
  • Age Calculate when user select DOB from date picker
  • DialogFragment doesn't show up
  • send file using default bluetooth application in android
  • regular expression in grep
  • I want to display seperate alerts for name and pass fields
  • RegExp word boundary with special characters (.) javascript
  • How to show a Progress Bar inside an AlertDialog Builder along with other elements without an XML?
  • Does iOS support Bluetooth SPP?
  • How do I get edittext value from a custom AlertDialog where retrieval of values is not in the onClic
  • Symfony2 FOSUserBundle error - FileLoaderImportCircularReferenceException
  • jquery styles not applied in dynamically creation
  • How to deal with overlapping X-axis labels in DOJO chart?
  • Handle Tab Key Press on WebBrowser Control and Prevent Switching between Html Elements
  • Draw circle on google maps by passing parameters to the url
  • Re-using zip iterator in python 3 [duplicate]
  • Get fragment activity outside of Fragment.OnCreateView()
  • Android in-app-billing. When to unregister the ResponseHandler?
  • Print multiple pages from TextBox
  • How to display video after getting from json?
  • Passing Data between VB.NET forms
  • Get the clicked item in android list
  • Pass data to a existing form
  • Bootstrap modal closes when dropdownlist inside fires selected index changed event
  • How to add an item to a ListView with each Button click
  • How to process binary stream in Wicket like Servlet?
  • C#, “Object reference not set to an instance of an object.” error
  • .net security exception
  • UIPickerView without IB?
  • Returning this from a constructor function in JS
  • dismiss Progress Dialog in another Activity … Android
  • How to remove all of a jQuery UI dialog when it is closed
  • Cassandra NoClassDefFoundError: com/google/common/util/concurrent/AsyncFunction
  • SqlCommand back up Database
  • how to upload multiple files in c# windows application
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • Alert pop up with LWUIT