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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:14:33+00:00 2026-05-26T05:14:33+00:00

I have a service that gets the location and sends it to a server,

  • 0

I have a service that gets the location and sends it to a server, also I have an activity that starts and stops the service with a button. When I start up the service all the buttons do not work and after a while the activity force closes giving the option to wait or close. what could be causing the problem?

  • 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-26T05:14:33+00:00Added an answer on May 26, 2026 at 5:14 am

    I did something like that before … I dont post the whole code, jsut the main thing. This wont run, i just want to give you the idea, of what to llok for and how to handle it.
    The magic is done in sendUpdatesToUI… I saved myself all the unimportant methods that are overwritten when you implement LocationListener – you know best, which of them you need.

    class:

    public class ServiceLocator extends Service implements LocationListener 
    public static final String BROADCAST_ACTION = "my.app.isgreat";
    private final Handler handler = new Handler();
    private LocationManager locationManager;
    Intent intent;
    
    public void onCreate() {
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        intent = new Intent(BROADCAST_ACTION);
    }
    
    public void onStart(Intent intent, int startId) {
        handler.removeCallbacks(sendUpdatesToUI);
        handler.postDelayed(sendUpdatesToUI, DEBUG_DELAY);
    
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                DEBUG_DELAY, 3, this);
    
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(sendUpdatesToUI);
        locationManager.removeUpdates(this);
        locationManager = null;
    

    }

    //Here is the second thread, that won'z freeze your UI
    //DisplayLogginInfo() sets all the values you wanna send
    private Runnable sendUpdatesToUI = new Runnable() {
    public void run() {
        DisplayLoggingInfo();
        handler.postDelayed(this, DEBUG_DELAY);
    }
    
    };
    
    private void DisplayLoggingInfo() {
        intent.putExtra("long", String.format("%.4f", lastLocation.getLongitude()));
        sendBroadcast(intent);
    }
    

    It probably won’t run that way, because I kicked out all the uninteresting stuff, but it should give you an idea, how to programm a locationthread, which won’t freeze your UI.

    Have fun

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

Sidebar

Related Questions

On my Apache server I have a PHP service that gets requests and generates
In my app, I have a service that gets the location of the device
I have a C# WCF service DLL that gets hosted by WcfSvcHost.exe when I
I have a perl variable $results that gets returned from a service. The value
In my app I've designed it to have a Service that gets data constantly
I have a background service that gets data from somewhere and likes to draw
I have an app that hits a REST service, gets some json and then
I have an android application that gets user location every 2 minutes using requestLocationUpdates
I have a web service that gets a string as parameter and returns string
Imagine this scenario: you have a WCF web service that gets hit up to

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.