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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:40:25+00:00 2026-06-01T14:40:25+00:00

I am using an Accelerometer in my application and I am wondering if I

  • 0

I am using an Accelerometer in my application and I am wondering if I can make it the way that accelerometer is only activates for a certain amount of time after the user has pressed a start button. It should stops when user press the stop button. It will essentially work as a pedometer which is part of a bigger application. This is the code used to implement the accelerometer:-

SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
    int sensorType = Sensor.TYPE_ACCELEROMETER;
    sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(sensorType),SensorManager.SENSOR_DELAY_NORMAL);

I have the code counting the steps which is:-

final SensorEventListener sensorListener = new SensorEventListener()
{

    public void onSensorChanged(SensorEvent event)
    {
            if(event.values[2]<3)
            {
                counter ++;
            }
            else if(event.values[2]>5)
            {
                counter --;
                counter ++;

            }
            sensorData.setText("Steps = "+ counter);

      }

      public void onAccuracyChanged(Sensor sensor, int accuracy){}
      };

I’m just wondering that since I’m counting the steps in the onSensorChanged method how do I limit this to only a button press state? Would it be possible to add a timer in to count how long has passed between the two button presses I mentioned earlier?

  • 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-01T14:40:26+00:00Added an answer on June 1, 2026 at 2:40 pm

    Yes, of course.

    Prepare manager:

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    

    Start accelerometer:

    mSensorManager.registerListener(this, mAccelerometer, 
         SensorManager.SENSOR_DELAY_NORMAL);
    

    Stop:

    mSensorManager.unregisterListener(this);
    

    Don’t forget unregister listener in onPause() method.

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

Sidebar

Related Questions

I am using android java to create an application that uses the accelerometer, i
I am using the IPhone's Accelerometer to make a object move. I want to
How can i set bounds so my image which moves using acclerometer can only
I am porting an app that I originally wrote using the accelerometer for IOS
Using the SensorManager I can find the x,y,z from the ACCELEROMETER. I can detect
im trying to make an speedometer using the accelerometer but for some reason the
I'm wondering if I can use (linear) accelerometer and compass to calculate velocity without
I'm using the accelerometer to move an object on my screen. It's only working
I am using the accelerometer to move a few UIImageViews around the screen, at
I am using the accelerometer function in my project and I need to exclude

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.