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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:56:38+00:00 2026-06-17T05:56:38+00:00

I’m using a sensor for my Android Application. I register the sensor with a

  • 0

I’m using a sensor for my Android Application. I register the sensor with a line of code:

mySensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL);

I have introduced a line of code to unregister the listener so it wont be running all time:

mySensorManager.unregisterListener(this);

So far it works, but i need to register it again when the application resumes. I need to know if my sensorManager has a registered listener so I can registered again or skit it. Does something like this can be done?:

if (mySensorManager.getRegisteredListenerList == null){ registerListener() } else { .. }
  • 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-17T05:56:39+00:00Added an answer on June 17, 2026 at 5:56 am

    As far as I know, there is no native way to check if you have already registered listener. I would not worry too much about this check since this check is already done by Android, so if you have already registered listener, Android is not gonna add the same listener twice:

    @SuppressWarnings("deprecation")
    private boolean registerLegacyListener(int legacyType, int type,
            SensorListener listener, int sensors, int rate)
        {
            if (listener == null) {
                return false;
            }
            boolean result = false;
            // Are we activating this legacy sensor?
            if ((sensors & legacyType) != 0) {
                // if so, find a suitable Sensor
                Sensor sensor = getDefaultSensor(type);
                if (sensor != null) {
                    // If we don't already have one, create a LegacyListener
                    // to wrap this listener and process the events as
                    // they are expected by legacy apps.
                    LegacyListener legacyListener = null;
                    synchronized (mLegacyListenersMap) {
                        legacyListener = mLegacyListenersMap.get(listener);
                        if (legacyListener == null) {
                            // we didn't find a LegacyListener for this client,
                            // create one, and put it in our list.
                            legacyListener = new LegacyListener(listener);
                            mLegacyListenersMap.put(listener, legacyListener);
                        }
                    }
                    // register this legacy sensor with this legacy listener
                    legacyListener.registerSensor(legacyType);
                    // and finally, register the legacy listener with the new apis
                    result = registerListener(legacyListener, sensor, rate);
                }
            }
            return result;
        }
    

    So you can call registerListener as many times as you want it will only be added once:)

    The same is applicable for unregister logic

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.