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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:00:10+00:00 2026-06-12T17:00:10+00:00

Gravity sensor values increases after each call of onSensorChanged(SensorEvent event) the values of event.

  • 0

Gravity sensor values increases after each call of onSensorChanged(SensorEvent event) the values of event. Values increases and after a little bit of time (about 1 min) reaches a NaN value. Could someone say why this is happening?
Code:

private void recordData(SensorEvent e) {
    String label;
    int currentSensorId = -1;
    switch (e.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        currentSensorId = 0;
        label = LOG_LABEL_ACCELEROMETER;
        break;
    case Sensor.TYPE_GYROSCOPE:
        label = LOG_LABEL_GYROSCOPER;
        currentSensorId = 1;
        break;
    case Sensor.TYPE_GRAVITY:
        label = LOG_LABEL_GRAVITY;
        currentSensorId = 2;
        break;
    case Sensor.TYPE_ROTATION_VECTOR:
        label = LOG_LABEL_ROTATION_VECTOR;
        currentSensorId = 3;
        break;
    default:
        label = "UNKNOWN SENSOR TYPE!";
        break;
    }
    if (currentSensorId == -1)
        return;

    // Force set events frequency to value from config,
    // cause sensor events minimal frequency = 0.2 sec.
    timePassed[currentSensorId] = System.currentTimeMillis()
            - lastSensorEventTime[currentSensorId];
    if (timePassed[currentSensorId] < Config.SENSOR_DELAY_MILLISEC) {
        return;
    } else {
        lastSensorEventTime[currentSensorId] = System.currentTimeMillis();
    }

    if (this.pauseRecordingData || checkSDCardMemory())
        return;
    fileWriter.writeEvent(label, System.currentTimeMillis(), e.values);
}

public void writeEvent(String eventSource, long timestamp, float[] values) {
        Log.d(TAG, "writeEvent(); eventSource = " + eventSource);       


    if ( !this.fileExists ) createNewFile();        
    try {       
        String valuesString = eventSource + "\t" + String.format( "%d\t", timestamp);

        for (int i = 0; i < values.length; i++) {
            valuesString += String.format( "%f\t",values[i]);
            Log.d(TAG, "writeEvent(); values[" + i + "] = " + values[i]);
    }           
        buffWriter.append(valuesString + "\n");
    } catch (IOException e1) {              
          e1.printStackTrace();
          Log.d(TAG,"RECORDING EVENT TO FILE FAILED!");
    }               
}
  • 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-12T17:00:12+00:00Added an answer on June 12, 2026 at 5:00 pm

    There are two possibilities:

    1. The most probable one: You have an error in your code, for example, you are never resetting the variable or making addition to the values (for details, please read http://developer.android.com/guide/topics/sensors/sensors_motion.html).

    2. Your gravity sensor is broken (to check that, try on another device).

    For more help, please post your code, how are you accessing and managing the values read from the gravity sensor.

    EDIT:

    As I mentioned, there war an error in your code. The sensor read delay should be set to one of the possible options:

    int     SENSOR_DELAY_FASTEST     get sensor data as fast as possible
    int     SENSOR_DELAY_GAME        rate suitable for games
    int     SENSOR_DELAY_NORMAL      rate (default) suitable for screen orientation changes
    int     SENSOR_DELAY_UI          rate suitable for the user interface 
    

    And not to a custom value !!!

    Thank you for finding the solution.

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

Sidebar

Related Questions

I know we can set the following values to the android:gravity and android:layout_gravity properties:
How do the different Gravity values effect PopupWindow.showAtLocation() in Android? I can't find good
I have software designed for 2.3.3 where I am using the gravity sensor. Code
I was reading through the sensor event documentation on the android developer site. I
Gravity forms allows for basic field calculations using merge tags, such as {Field 1:1}
Iphone accelerometer provides user acceleration and gravity reading? It's clear from the apple guide
I want to add ImageView to FrameLayout with Gravity or margins. but FramLayout and
I have a problem with Map objects, while using Gravity. All messages works ok,
I've implemented the Barnes-Hut gravity algorithm in C as follows: Build a tree of
I am making a test landing page and using a Gravity Form for the

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.