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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:13:48+00:00 2026-06-07T18:13:48+00:00

I’ve been trying to get display a compass and a distance between my position

  • 0

I’ve been trying to get display a compass and a distance between my position and another position on the map.

Almost exactly like:

Android: compass + distance in a listview

I understood the code, set up a listener for detecting orientation changes, and also calculated the distance.

Furthermore, I am displaying the correct distance in my ListView (I already had a custom adapter). Thats a little clarification as to where I am.

This is my problem: I am updating the ListView every second through the listener, by changing the values of the actual list the adapter is looking at and calling:

    notifyDataSetChanged();

Calling this every second is making the ListView laggy, just as I had expected. I can get away with updating the distance every 10 seconds or so (or a little more). However, I have to update the list far more often to have a live compass as well. I’ve been looking around and I couldn’t really find anything, I would appreciate all the help I can get. Thank you!

Side note: If you need to see any code I’ve written, I’m willing to paste it here. There are many parts to it so I will do it on demand.

  • 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-07T18:13:50+00:00Added an answer on June 7, 2026 at 6:13 pm

    IMHO you should omit the whole list view and adapter. The best approach would be creation of own view for elements which should be updated frequently.

    For example create view called HeadingView which will have setAbsouluteheading. This setter would be used by adapter. Then view would implement also SensorEventListener to observe sensors and get device heading.
    When relative direction should change HeadingView would update it self. Problem in this case is detection when HeadingView should register/unregister itself for sensor events. onWindowFocusChanged looks promising and onWindowSystemUiVisibilityChanged (API level 16) is what you need.

    Remember that there is a danger that there may be some corner cases and your view will not unregistered itself from observing sensors when it should. This may lead to terrible power consumption in sleep mode, so remember to do extensive testing.

    There are probably alternative ways to perform communication between this HeadingView and sensors, but I think in general my concept is good solution.


    Update:

    I’ve come up with better idea how to communicate with this HeadingView without problems to detecting when disable sensors and not causing memory leak. The answer is week reference or more exactly WeakHashMap.

    HeadingView view is more or less as I explained before, but in constructor it notifies YourActivity about its existence. So it would bes something like that:

    public class HeadingView extends View {
    
        public HeadingView(Context context) {
            super(context);
    
            YourActivity activity = (YourActivity) context;
            activity.addWeekSensorObserver(this);
        }
    }
    

    And your activity:

    public class YourActivity extends Activity implements SensorEventListener {
        // there is no WeekSet and WeakHashMap is more handy then List<WeakReference>
        private final  WeakHashMap<HeadingView, Object> sensorObservers = new WeakHashMap<HeadingView, Object>();
        public void addWeekSensorObserver(HeadingView headingView) {
            sensorObservers.put(headingView, null);
        }
    
        private updateHeadings(float[] deviceHeading) {
            Set<HeadingView> keySet = sensorObservers.keySet();
            for (HeadingView headingView : keySet) {
                headingView.setDeviceHeading(deviceHeading);
            }
        }
    }
    

    Standard sensor handling in activity now applies so detecting when to disable sensor is not a problem and you don’t have to worry about memory leaks. I suspect that even you don’t have to alter code a lot :).
    To make it nicer you can define interface.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace

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.