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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:12:44+00:00 2026-06-16T12:12:44+00:00

I want to start a service which will run in the background, and will

  • 0

I want to start a service which will run in the background, and will show latitude and longitude every 30 to 45 seconds.
Below is my code which I’m using:

public class LocalService extends Service implements LocationListener {
    private final static String TAG = "LocalService";
    LocationManager lm;


    public LocalService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        subscribeToLocationUpdates();
    }

    public void onLocationChanged(Location loc) {
        Log.d(TAG, loc.toString());
        Toast.makeText(getApplicationContext(), loc.getLatitude() + " - " + loc.getLongitude(), Toast.LENGTH_LONG).show();
        Log.i("Location", loc.getLatitude() + " - " + loc.getLongitude());
    }

    public void onProviderEnabled(String s) {
    }

    public void onProviderDisabled(String s) {
    }

    public void onStatusChanged(String s, int i, Bundle b) {
    }

    public void subscribeToLocationUpdates() {
        this.lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30, 0, this);
    }
}

I’m calling my service like this:

startService(new Intent(TimerServiceActivity.this,
         LocalService.class));

This is my manifest code for service:

<service android:name="LocalService" >

Whenever I am running this code it gives me an error message that unfortunately, TimerService has stopped.

  • 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-16T12:12:45+00:00Added an answer on June 16, 2026 at 12:12 pm

    Do you have the permissions added in your manifest?

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    

    I instead highly recommend using this library optimized for battery usage and is rather simple to use:

    http://code.google.com/p/little-fluffy-location-library/

    Based on the concepts in, and some code adapted from,
    android-protips-location by Reto Meier, from his blog post A Deep Dive
    Into Location.

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

Sidebar

Related Questions

I want to create a service which will run on a separate thread (not
I am developing an application in which I start a service which will run
I want to develop a application which will continue to run in background for
I have an AsyncTask and on the background I want to start Service that
I develop a Windows Service that will run under SYSTEM user. So I want
I have a windows service which will start and stop the execution of some
I am creating a Java service which will run within a web servlet container
I want to write a simple web service in groovy/grails which will retun some
When I want to start the tomcat service I write /etc/rc.d/init.d/tomcat start However it
I want to start an activity when the service is ran for the first

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.