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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:21:27+00:00 2026-05-23T04:21:27+00:00

I am using Motorola Xoom with WiFi for application development purpose.I have tried to

  • 0

I am using Motorola Xoom with WiFi for application development purpose.I have tried to implement code to create speedometer using accelerometer but the only problem I am facing is that JAVA compiler is deprecating “Sensorlistener”. I need some help to fix it. My using following codes for JAVA and .xml layout

JAVA

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Context;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

public class Speedometer extends Activity {

  Handler handler = new Handler();

  SensorManager sensorManager;
    TextView myTextView;

    float appliedAcceleration = 0;
    float currentAcceleration = 0;
    float velocity = 0;
    Date lastUpdate;    

    @Override
    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      setContentView(R.layout.main);

      myTextView = (TextView)findViewById(R.id.myTextView);
      lastUpdate = new Date(System.currentTimeMillis());

      sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
      sensorManager.registerListener(sensorListener, SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_FASTEST);

      Timer updateTimer = new Timer("velocityUpdate");
      updateTimer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
          updateGUI();
        }
      }, 0, 1000);
    }

    private void updateGUI() {
      // Convert from meters per second to miles per hour.
      final double mph = (Math.round(100*velocity / 1.6 * 3.6))/100;

      // Update the GUI
      handler.post(new Runnable() {
      public void run() {
          myTextView.setText(String.valueOf(mph) + "mph");
      }
    });
    }

  private void updateVelocity() {
      // Calculate how long this acceleration has been applied.
      Date timeNow = new Date(System.currentTimeMillis());
      long timeDelta = timeNow.getTime()-lastUpdate.getTime();
      lastUpdate.setTime(timeNow.getTime());

      // Calculate the change in velocity at the 
      // current acceleration since the last update. 
      float deltaVelocity = appliedAcceleration * (timeDelta/1000);
      appliedAcceleration = currentAcceleration;

      // Add the velocity change to the current velocity.
      velocity += deltaVelocity;
    }

  private final SensorListener sensorListener = new SensorListener() {

    double calibration = Double.NaN;

    public void onSensorChanged(int sensor, float[] values) {        
      double x = values[SensorManager.DATA_X];
      double y = values[SensorManager.DATA_Y];
      double z = values[SensorManager.DATA_Z];

      double a = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)); 

      if (calibration == Double.NaN)
        calibration = a;
      else {
        updateVelocity();
        currentAcceleration = (float)a;
      }
    }

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

.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView android:id="@+id/myTextView"
    android:gravity="center"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:textStyle="bold" 
    android:textSize="40sp" 
    android:text="CENTER" 
    android:editable="false" 
    android:singleLine="true" 
    android:layout_margin="10px"/>
  />
</LinearLayout>

I will be grateful for helpful suggestions.

  • 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-05-23T04:21:28+00:00Added an answer on May 23, 2026 at 4:21 am

    The documentation spells it out, just use SensorEventListener instead.

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

Sidebar

Related Questions

I have an HTML5 page using CSS3 and SVG graphics in development. I tried
i have created application using layout font sizes in pixels font and other layout
I'm using the SIP stack in Android 2.3.x+ (actually testing on Motorola Xoom though)
My code works as expected on smaller and bigger devices (Motorola Xoom, Samsung Galaxy
I'm trying to crosscompile simple SDL application for ARM processor. I'm using Motorola A1200
I am using Motodev , an Eclipse-based development tool for Java ME / Motorola.
I'm using android 3.1 on a Motorola xoom (SDK Lvl 12), and I was
Using a Motorola Atrix 4G, it is not able to download the application I
I am developing a small app for a Motorola 9090-G using .net compact framework
I'm testing an android application with a long running service. I'm using Eclipse and

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.