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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:43:04+00:00 2026-05-17T01:43:04+00:00

I am developing an app for android mobiles that communicates with a json/rest web

  • 0

I am developing an app for android mobiles that communicates with a json/rest web service. I need to make certain kinds of calls periodically to the server to check for some information.
Within that context I might need also to query the GPS for the current position. I’m quite undecided to use a Local Service, since I don’t know very well how to deal with them, in fact I need to retrieve those data periodically and refresh a MapView accordingly.
I heard that I can use PendingIntents,in the service, associate this data as a payload and send them to a broadcast receiver which unpack the data and refresh the UI, I heard also that this is a bad design approach because of what broadcast receiver are intended to be used for.
does anybody have some useful hints?

  • 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-17T01:43:05+00:00Added an answer on May 17, 2026 at 1:43 am

    first you have to deal with google maps since you will display a mapview. Have a look at this
    Using Google Maps in Android on mobiForge.

    Second you need a class that provides gps data. It is simple to get location data and update UI using message handler. Here is an example:

    public MyGPS implements LocationListener{
    
        public LocationManager lm = null;
        private MainActivity SystemService = null;
        //lat, lng
        private double mLongitude = 0;
        private double mLatitude = 0;
    
        public MyGPS(MainActivity sservice){
            this.SystemService = sservice;
            this.startLocationService();
        }
    
        public void startLocationService(){
            this.lm = (LocationManager) this.SystemService.getSystemService(Context.LOCATION_SERVICE);
            this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 5, this);
        }
    
        public void onLocationChanged(Location location) {
            location = this.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            try {
                this.mLongitude = location.getLongitude();
                this.mLatitude = location.getLatitude();
            } catch (NullPointerException e) {
                Log.i("Null pointer exception " + mLongitude + "," + mLatitude, null);
            }
        }
    }
    

    In your onCreate method make an instance of this class and the locationlistener will start to listen for gps updates. But you can not access lng and lat since you do not know from your activity wheather they are set or null. So you need a handler that sends a message to your main activity when lat and lng are set:

    Modify in the following method:

    public void onLocationChanged(Location location) {
            location = this.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            try {
                this.mLongitude = location.getLongitude();
                this.mLatitude = location.getLatitude();
                Message msg = Message.obtain();
                msg.what = UPDATE_LOCATION;
                this.SystemService.myViewUpdateHandler.sendMessage(msg);
            } catch (NullPointerException e) {
                Log.i("Null pointer exception " + mLongitude + "," + mLatitude, null);
            }
        }
    

    In your main activity add this:

    Handler myViewUpdateHandler = new Handler(){
    
            public void handleMessage(Message msg) {
                    switch (msg.what) {
                    case UPDATE_LOCATION:
                    //access lat and lng   
             }));
                   }
    
                    super.handleMessage(msg);
            }
    };
    

    Since the handler is in your mapactivity you can update your UI easily in the handler itself. Everytime gps data is aviable a message is triggered and received by the handler.

    Developing a REST API is a very interesting thing. A easy way is to have a php script on a webserver that on request returns some json data. If you want to develope such a service this tutorial might help you, link.

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

Sidebar

Related Questions

No related questions found

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.