Dialog Save at android, startup

146 views Asked by At

I'm trying to make a webview application, and I'm stuck somewhere.

When I start the application first time (for installation) it should ask a question, like:

Have you read the terms of service? Yes No

If I choose "Yes", the app should remember it, and shouldn't ask again if the program is launched again sometime later. If I choose "No", the application should terminate, and it should ask the same question next time the application has been started.

I'm really stuck, and I couldn't find a tutorial like this.

2

There are 2 answers

1
jsb On BEST ANSWER

I would create a loading activity that would check to see if its asked the user to accept the rights (TOS) and then if it has go into the main activity, and if not display it and wait. Try this in oncreate of the loading activity

SharedPreferences sp = getSharedPreferences("TOS", Context.MODE_PRIVATE);
boolean hasAccepted = sp.getBoolean("accepted", false);
if(hasAccepted)
{
    //start next activity
}else {
    ///display the TOS
}

Then create a listener for the yes/no button that calls these methods

public void onClickYes(){
 SharedPreferences sp = getSharedPreferences("TOS", Context.MODE_PRIVATE);
 sp.edit().putBoolean("accepted", true).commit();
}

public void onClickNo(){
  finish();
}

What this is doing is when the app loads it tries to get the SharedPreference "accepted". If it can't find it then it uses the default value of false hence (sp.getBoolean("accepted", false"). Then if the user accepts the tos you store the SharedPreference of "accepted" as true. So next time the app loads it will be able to find the preference and return true, therefore not displaying the TOS

0
Ryan M. On

I would store a property locally to read at launch. Here is the API http://developer.android.com/reference/java/util/Properties.html