Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:54:50+00:00 2026-06-08T14:54:50+00:00

I am trying to have a disclaimer pop up when the app is first

  • 0

I am trying to have a disclaimer pop up when the app is first run, and after each update. I did a bunch of googling and reviewed some questions here as well, and this is what my code looks like:

SharedPreferences pref = getSharedPreferences("Preferences", MODE_PRIVATE);
SharedPreferences.Editor edit = pref.edit();
String lver = pref.getString("Version", "");
String ver = this.getString(R.string.version);
if(ver != lver)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Disclaimer")
        .setMessage(this.getString(R.string.disclaimer))
        .setCancelable(false)
        .setPositiveButton("Accept", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                accepted = true;
                dialog.cancel();
            }
        })
        .setNegativeButton("Decline", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                MainMenu.this.finish();
            }
        });
    AlertDialog disc = builder.create();
    disc.show();
    if(accepted == true)
    {
        edit.putString("Version", this.getString(R.string.version));
        edit.commit();
    }
}

This code actually worked at first, but when I changed my apps starting activity, and moved this code from the original starting activity to the new one, it no longer works. The disclaimer appears on every run.

I want the popup only to show on first run and after updates. What do I need to do to achieve this? I am very frustrated and confused by the fact that it was working, then wasnt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:54:58+00:00Added an answer on June 8, 2026 at 2:54 pm

    Comparing Strings with .equals() is the correct way (see: How do I compare strings in Java? for a good explanation) , although because I’m not sure how the android internals work and you said it worked before, that isn’t your problem. Your problem is that your check

    if (accepted == true) {/** code */}
    

    isn’t run on the on click listener. Because it isn’t, that thread (I’m assuming it spawns a new thread to show the dialog) keeps running.

    I’m also assuming before you moved this code, you had declared a

    boolean accepted = true; //or initialized it to true somewhere
    

    But when you moved it you didn’t reinitialize it. Now, because the default value of a primitive is false, in your new code it gets to the check before you press a dialog button, and never commit the new version.

    My advice would be put what’s in the

    accepted == true
    

    block simply into your listener for the positive button click.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to have my PHP script return some SQL table queries. Here's my script
Disclaimer: I have already seen the following questions and their solutions did not apply
We are trying to debug some legacy code. We have found that we are
Afternoon, I am trying have an HTML file containing a frameset which contains two
I have trying to learn MVC4 Web API. I am running my project from
I have a cache directory I'm trying to have ignored by git which lives
I'm trying to have images fade in with css3 once they're loaded. The problem
I am trying to have a table like this: Manager Expert Adminis. Staff Dept
I am trying to have a method that takes in a username and will
I'm trying to have a fixed width sidebar with a 100% height, next to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.