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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:43:19+00:00 2026-06-17T08:43:19+00:00

I have written the following lines to record accelerometer data in a file with

  • 0

I have written the following lines to record accelerometer data in a file with a button click

startButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {


            final SensorEventListener mySensorEventListener = new SensorEventListener() { 
                public void onSensorChanged(SensorEvent sensorEvent) {
                if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {


                xAxis_lateralA = sensorEvent.values[0]; 
                yAxis_longitudinalA = sensorEvent.values[1]; 
                zAxis_verticalA = sensorEvent.values[2]; // TODO apply the acceleration changes to your application.
                textView.append("\nACC_x = "+ xAxis_lateralA + ", ACC_y = "+yAxis_longitudinalA+ ", ACC_z = " + zAxis_verticalA);
                acc+="\n"+xAxis_lateralA + ", "+ yAxis_longitudinalA+", "+zAxis_verticalA;

                try {
                    File myFile = new File("/sdcard/acc.txt");
                    myFile.createNewFile();
                    FileOutputStream fOut = new FileOutputStream(myFile);
                    OutputStreamWriter myOutWriter = 
                                            new OutputStreamWriter(fOut);
                    myOutWriter.append(acc);
                    myOutWriter.close();
                    fOut.close();
                    Toast.makeText(getBaseContext(),
                            "Done writing SD 'acc.txt'",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }

                }
            }
                @Override
                public void onAccuracyChanged(Sensor sensor, int accuracy) {
                    // TODO Auto-generated method stub

                }
            };
            // write on SD card file data in the text box
            sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE); 
            int sensorType = Sensor.TYPE_ACCELEROMETER; 
            sm.registerListener(mySensorEventListener,sm.getDefaultSensor(sensorType), SensorManager.SENSOR_DELAY_NORMAL);

        }// onClick
        });

Now I want it to stop recording the data with another button click. For example –

stopButton.setOnClickListener(new OnClickListener() {

     public void onClick(View v) {
        int sensorType = Sensor.TYPE_ACCELEROMETER; 
        sm.unregisterListener(listener, sensor)
     }// onClick
  }); // btnstopButton
}

Wanted to use unregisterListener but most of the time it is saying deprecated.

Can anyone help please?

  • 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-17T08:43:20+00:00Added an answer on June 17, 2026 at 8:43 am

    I think you want to declare your SensorEventListener object outside of the onClick() method so you can unregister it in the other onClick() method:

    sm.unregisterListener(mySensorEventListener, sensorType);
    

    That’s the method signature you want to use according to the docs.

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

Sidebar

Related Questions

I have written following lines to click all links in fetched page but it
I have written the following code, CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(@C:\Users\XXX\Desktop\Backup1\Project\ReportsFolder\ReportSalesInvoice.rpt); Report works
I have written a following code to get just the file name without extension
I have a .csv file with records written in the following form: 2010-04-20 15:15:00,8.9915176259e+00,8.8562623697e+00
I have written following lines of code and seems everything is OK, however when
In my function for displaying text in textarea,i have written following lines of code
I have an handler in a Python page written following the guide lines of
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
i have written the following code class Program { static void Main(string[] args) {

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.