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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:08:06+00:00 2026-06-06T07:08:06+00:00

In my app, I am using the light and proximity sensor to detect phone

  • 0

In my app, I am using the light and proximity sensor to detect phone out of pocket functionality and then unregistering the SensorManager when their detection is complete. But even when the CPU usage by the app shows just 1-2 sec usage, the battery usage always shows my app as no. 1 app in the list which is worrying.

I have used the SensorManager.unRegisterListener and also set SensorManager = null, but the situation remains the same.

I have read, that due to some bug, the sensors are not unregistered correctly. Any good way to dispose the sensors correctly ?

Pls guide.
Omkar Ghaisas

Updated with Code sample from app –

@Override
protected void onPause()
{
    super.onPause();
    unHookReceiver();
}

private void unHookReceiver()
{
    if (r != null)
    {
        unregisterReceiver(r);
        if(GetProximityPreference("EnableReceiveByProximity"))
        {
            mySensorManager.unregisterListener(proximitySensorEventListener);
            mySensorManager.unregisterListener(lightSensorEventListener);
            mySensorManager = null;
            FileUtils.appendLog(FileUtils.GetCurrentDateTime() + " Power Consumption Log End");
            FileUtils.appendLog("------------------------------------------------");
        }
        r = null;
    }
}

I am also setting the sensorManager = null as per one suggestion from one post on stackpverflow, but even that doesn’t help. In spite of calling the cleanup code, the battery usage is still very high. The app by itself should not be using much battery as its a very simple app with just one broadcast receiver and one activity, but within the activity, I invoke the Light and Proximity sensors and I doubt those are causing the spike in battery usage. Not sure why though.

Any help is highly appreciable.

  • 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-06T07:08:08+00:00Added an answer on June 6, 2026 at 7:08 am

    I was able to resolve this by correctly matching when the listeners were registered and when they were unregistered. Perhaps, initially the listeners weren’t getting properly unregistered in all Call conditions (incoming call, outgoing call, missed call etc), so even when the activity closed, the listeners were still listening for events thus unnecessarily consuming power.

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

Sidebar

Related Questions

I'm using MVVM Light to build a WP7 (Windows Phone 7) application. I wish
ImageScience is cool and light. I am using it in my sinatra app. But
Building a WP7 app using MVVM light for my view models. I'm using the
I have a WPF/MVVM (using MVVM-Light) app setup with a ComboBox that is inside
I'm making an app for windows phone 7 (using Visual Studio 2010 Express for
I've data bound a ListBox in my MVVM Light Windows Phone 7 app, and
I currently develop a metro style app using mvvm light framework. I have some
I am planning to have an app that is using the light scheme regardless
Possible Duplicate: Transparent, borderless ProgressDialog I'm using Theme.Light in my app. While using Progress
I am developing an app using jquery mobile and last issue to be solved

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.