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

  • Home
  • SEARCH
  • 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 9080351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:03:36+00:00 2026-06-16T20:03:36+00:00

I have a class that generates the phone location and it updates a TextView

  • 0

I have a class that generates the phone location and it updates a TextView every time a new location has retrieved.
We will name this class as Track.

The Track class contains a sendLocation object which is a Thread.
The sendLocation contatins a Track object and it checks every x time if the TextView has changed(the Track class got a method that returns the TextView string), how?

It save the last address in a string and compares between the last address and the Text View address every x time, if they are diffrent it sends this string to my db.
I do that to avoid duplicates.

My question is, how come it keeps sending same addresses to my db?I mean comparing strings is pretty simple.
Here is some code:

if(!t1.getAddress().equals(lastAddress))
{
    lastAddress = t1.getAddress();
    //send last address to the db
    //sleep for a while
}

t1 is a Track instance.

And here is the getAddress method in Track:

public String getAddress()
{
    return this.mAddress.getText().toString();
}

What’s is wrong?it’s a simple string comparing!!

  • 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-16T20:03:37+00:00Added an answer on June 16, 2026 at 8:03 pm

    You are probably having a race codition. The variable that saves lastAddress is still not updated with the latest value when you’re comparing.

    In a multithread program different threads saves copies of the same shared variable for efficiency. This copy will be updated from time to time, but does not guarantee that all of your threads will see the same value every time they access it. For that, you have to use synchronized in the blocks where you update/read the variable, or set it to be volatile, making all threads points to the same value of variable instead of having a copy of its own.


    EDIT:

    A good link to understand more about what may be happening to you: Threading Stories: Volatile and Synchronized

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

Sidebar

Related Questions

I have a php class that generates a map image depending on my db
I have this c# class that calculates n choose k and then generates all
I have a class that has the following property that is generated by the
I have a constructor (for an auto generated class) that has 255 paremeters. Using
I have a buffer in class 'bufferClass' that will generate a signal to tell
I have a class that generates PDF with Prawn: class CustomersReport < Prawn::Document def
My app has a screen that refreshes every second in AsyncTask: class BarRefresh extends
I have a span that is generated through javascript, with its css class as
I have class that extend FragmentActivity in it I add fragment to layout as
I have class that looks like this: class A { public: class variables_map vm

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.