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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:14:42+00:00 2026-05-29T11:14:42+00:00

Hello I am learning a bit of droid programming, specifically for class I am

  • 0

Hello I am learning a bit of droid programming, specifically for class I am trying to make a game. I am trying to use the orientation sensor to get input to use in the game, the problem is that I never get an onchange event to happen. I started running the debugger and found out that register listener always fails and spits back false, this leaves my sensor event listener null, and me confused. since I have been working on this for literally 13 hours I suppose I’ll swallow some pride and ask you guys for help. Here is the code, I have stripped basically everything out from it. I just don’t get sensors.

Thank you all for any help I recieve

      package edu.hiram.cpsc172;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;



@SuppressWarnings("deprecation")
public class GraphView extends View implements SensorEventListener 
{

    private Canvas screen;


    private boolean t = false;
    private float headingAngle;
    private float pitchAngle;
    private float rollAngle;
    private  SensorManager mSensorManager;
    private  Sensor mGyro;
    private SensorEventListener glisten;

    private Context context; // I have no idea what this actually means, but hey why not try? whats the worst that can happen?




       public GraphView(Context con) 
       {
           super(con);
           this.context = con; // so I have a context outside the constructor, it is needed for stuff.
                               // I find it amusing that although I have no clue what this stuff does I am 
                               // recognizing patterns in how context is used.

           //Annoyingly I have to do a few initializations in on draw, I dislike that. 

       }  





       // Called back to draw the view. Also called by invalidate()
       @Override
       protected void onDraw(Canvas canvas) 
       {

               //gives me a canvas object to play with if I want, and draws my background 
              screen = canvas;



            {
               mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
                  mGyro = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); 
        boolean x = true;        
         x =     mSensorManager.registerListener(glisten, mGyro, Sensor.TYPE_ORIENTATION); //this always returns false, and glisten stays null
                 x = x;
                 x=x; //I realize this does nothing, but it gives me places to set breakpoints, and check the line output
                 x = x;
            }




         try {  
                Thread.sleep(10);  
            } 
         catch (InterruptedException e) 
         {

         }

         invalidate();
      }







       @Override
        public void onSensorChanged(SensorEvent event)     
       {

           {
            headingAngle=event.values[0];
            pitchAngle= event.values[1];
            rollAngle=event.values[2];
           t= true;
           }
          Paint paint = new Paint();
          paint.setColor(Color.WHITE);
           screen.drawText("sensors responded", 100, 100, paint);
    }









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

    }
}

After changing the line the listener gets registered but onSensorChange never fires. I hope editing to ask is right, or is this a new question? Thanks again

  • 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-29T11:14:42+00:00Added an answer on May 29, 2026 at 11:14 am

    You never initialized glisten. But, what you really want to do, since you implement the interface, is to just use this:

      mSensorManager.registerListener(this, mGyro, Sensor.TYPE_ORIENTATION);
    

    See the sample.

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

Sidebar

Related Questions

hello im new and learning javascript. I'm trying to make a program of addition
hello im trying to make somekind of mvc, well at least for learning propose,
Hello I am compiling a program with make but I get the error of
Hello I'm learning Rails3 so I start to use gem Bundler ( http://github.com/carlhuda/bundler )
Hello everyone I'm currently implementing a simple programming language for learning experience but I'm
Hello i want to use NoSql database in my rails/django application for learning point
Hello everyone I am just learning my first programming language and have just corrected
Hello I am just learning postGIS and thus postgresql (9.1) and am trying to
Hello i'm learning a bit JSP and i have a problem with the code
Hello i am learning qt and trying to upload a file using QFtp i

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.