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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:41:59+00:00 2026-05-30T10:41:59+00:00

I follow this post What is the simplest and most robust way to get

  • 0

I follow this post What is the simplest and most robust way to get the user's current location on Android?

I have many questions about the post, but unfortunately I don’t have enough reputation to reply there, so I have to create a separate post. Sorry for any inconvenience.

Copy and past the code into my app and it works on my Samsung S2, but doesn’t work in the emulator (2.3).

My questions:

  1. When run in the emulator, the code never reach the onLocationChanged() methods, instead it will wait for 20 sec (timeout set by the timer1) to start run() of GetLastLocation. Why?

  2. Now, the run() method of GetLastLocation class is always called, and I got the exception above.

    (E/AndroidRuntime(436): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.).

I guess the error occurs in my code:

    public LocationResult locationResult = new LocationResult()
    {
        @Override
        public void gotLocation(final Location location)
        {
            Log.i(LOG_TAG, "gotLocation");
            if (location == null)
            {
                Log.i(LOG_TAG, "Cannot get location");
            }
            else
            {
                Log.i(LOG_TAG, "Lat: " + location.getLatitude() + " Long:" + location.getLongitude());
                tv = (TextView) findViewById(R.id.my_text); // <<< error here!!!
                            tv.setText(lat + "," + lon);
            }
        }
    };

TextView tv is initialized in my main Activity, which calls MyLocation myLocation = new MyLocation(); and myLocation.getLocation(this, locationResult);. The design is the same with that of the post. I wonder if the run() of GetLastLocation is called in another thread? Why is this? Has anyone got the same issue?

Thanks a lot!

  • 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-05-30T10:42:00+00:00Added an answer on May 30, 2026 at 10:42 am

    When using an emulator, you need to set your current location to it. It can be done with a few different ways. Se them here. I think the simplest way to start testing is to use the telnet and geo commands.

    As you can use findViewById I suppose you are in the inner class of some Activity. So, use the runOnUiThread method to update your views

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            tv = (TextView) findViewById(R.id.my_text); 
            tv.setText(lat + "," + lon);
        }
    });
    

    In the sample code, location updates are received through a timer task, that’s why it is running in a separate thread.

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

Sidebar

Related Questions

I have follow this post to make ImageButton in android android image button The
This post if a follow-up question to mt previous post: Android RESTful Web application
This question is a follow up to this post: What is the most efficient/elegant
As a follow up to this post: https://stackoverflow.com/questions/521432/best-jquery-rounded-corners-script Assuming jQuery is already being included,
This is a follow up question to this post I have two models: CarType.cs
I have been trying to follow the example in this post . Since I
I've been trying to follow this blog post to get my python version back
I follow this link https://github.com/RestKit/RestKit/wiki/Posting-NSDictionary-as-JSON to create the json post, and get back json
this is a follow up to this post . Basically I need to get
This question is in follow up to this post Grails one to many relationship

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.