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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:12:53+00:00 2026-05-25T15:12:53+00:00

i am working on sample application.In this application i would like to get updated

  • 0

i am working on sample application.In this application i would like to get updated location latitude and longitude when a user moving with android mobile on a way.I have implemented Location Manager class as follows :

 private LocationManager locationManager;
 private LocationListener locationListener;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);    

    locationListener = new GPSLocationListener();

    locationManager.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, 
        0, 
        0, 
        locationListener);
    }

       private class GPSLocationListener implements LocationListener 
{
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
       Toast.makeText(getBaseContext(), 
                    "Latitude: " + location.getLatitude() + 
                    " Longitude: " + location.getLongitude(), 
                    Toast.LENGTH_SHORT).show();
           }
        } 

}

How to get updated location latitude and longitude from back ground ?

please any body help me.

  • 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-25T15:12:54+00:00Added an answer on May 25, 2026 at 3:12 pm

    If you are intending to get the latitude and longitude while your application is not running, you can use a Service which get the latitude and longitude in background and do whatever task you want to. And also don’t forget to remove updates when not needed because getting updates is very costly operation in terms of device battery use.

    One more thing, you don’t need to check the location for null value because onLocationChanged() will be called only when a location is got by the your provider.

    Although I am also new to android. This may help you. You must see the android documentation what these Service class methods actually do and when they are called.
    This is not completed code. You have implement the locationlistener in this yourself. This is just an example program which shows a normal class:

    import java.util.Timer;
    import java.util.TimerTask;
    import android.app.Service;
    import android.content.Intent;
    import android.os.IBinder;
    import android.util.Log;
    
    public class BackService extends Service {
    
    private MyTimerTask mTimerTask;
    private Timer mTimer;
    
    @Override
    public void onCreate() {
        mTimer = new Timer();
        mTimerTask = new MyTimerTask();
    } 
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    
        mTimer.schedule(mTimerTask, 0, 500);
        Log.d("onStartCommand","onStartCommand called...");
        return START_STICKY;
    }
    
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    
    private class MyTimerTask extends TimerTask {
    
        @Override
        public void run() {
            // TODO Auto-generated method stub
            Log.i("BackService","BackService is running...");
            doSomethingWithLocation();
        }
    
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with the sample Home application project on http://developer.android.com/resources/samples/Home/index.html I've added another
We are creating sample application for windows mobile using Rijndael algorithm. Its working fine.
I have a little sample application I was working on trying to get some
I have a decent working web application (Java/Servlet/Jsp) that I would like to improve
I'm working on a plugin system. Some plugins need user input. I would like
I am currently working on a sample application which uses QNetworkAccessManager to send the
I'm working on a side project that would be a simple web application to
I'm working on a beta release of an application. This is a Java app
I would like to have my Spring MVC application mapped to the following extension
I have a web app of which I would like to create a mobile

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.