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 8011199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:57:32+00:00 2026-06-04T18:57:32+00:00

I have a method that checks for achievements and I am trying to get

  • 0

I have a method that checks for achievements and I am trying to get it to work properly. It takes a String and converts it to a long and then checks against a String value in the database ( Which is converted to long )

here is the code:

public boolean checkAchievements(String timeString) {   
    long timeInt = Long.parseLong(timeString);
    boolean newAchievement = false;
    SQLiteDatabase db = this.getWritableDatabase();

    Cursor cursor = db.rawQuery("SELECT millis FROM records ORDER BY CAST(millis as SIGNED) DESC", null);
    cursor.moveToFirst();
    long topTime = Long.parseLong(cursor.getString(0));
    cursor.close();

    if (timeInt > topTime) {
        db.rawQuery("update achievements set completed='yes' where name='Beat top record'", null);
        newAchievement = true;
    }

    db.close();

    return newAchievement;
}

Ihe timeString is the current time in milliseconds grabbed from the calendar and converted into a string from a long. I have no idea why this function keeps returning true especially when i know for a fact that timeInt is not greater than topTime.

also, even though this function is returning true, that update query isn’t even running because i checked the database and the completed value is still “no” where name=”Beat top record”.

  • 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-04T18:57:33+00:00Added an answer on June 4, 2026 at 6:57 pm

    Your method is returning true which is correct as per the condition. Let me explain you in details.

    as you said in question your timeString variable contains the current milliseconds which is a long value of milliseconds since 1st Jan 1900. Your time value in database is the old one than the current time ( i am assuming that, as you haven’t given its value in question ). So suppose you have top time is of yesterday ( i.e. 31st May 2012 ). Now when you compare this value with today’s current time, your method is going to return true which is correct itself.

    for checking the false value i would like to suggest you to store some future time like greater than the today’s date ( i.e. 1st June 2012 ) and the execute the method, it will surely return false value.

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

Sidebar

Related Questions

I have a method that takes a string value as a parameter and then
I have a method that checks if a type is generic and then checks
I have a method that checks spots in a 2D array, and it also
i currently have a method that checks what is around the centre item in
I have a method that takes a list of entities ( Class es) and
I have a method that returns a list of type string. I want to
I have a method that takes an array of queries, and I need to
I have a method that will receive a string , but before I can
I have a method that checks certain things and returns a Boolean based on
So I have a method that checks for internet connection, but only during the

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.