Android onSensorChanged wont work
<p>i am making a very basic tilt game in android with java, i have added the Bitmap,which is the graphic for the football, however, this wont move when i tilt the phone and it should, could anyone please tell me what is wrong with my code?</p>

<p>This is the class to create the ball</p>

<pre><code>package droid.pkg;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.View;

public class BallView extends View {

    public float mX;
    public float mY;
    public int mW;
    public int mH;
    private final int mR = 15;

    //construct new ball object
    Bitmap sball;
    public BallView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    sball = BitmapFactory.decodeResource(getResources(),R.drawable.player);
    this.mX = mX;
    this.mY = mY;
    }

   @Override
   protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawBitmap(sball, (canvas.getWidth()/2 - 40),canvas.getHeight() -130,null);
   }
   public int getPlayerW() {
       mW = sball.getWidth();

      return mW;

   }
   public int getPlayerH(){
       mH = sball.getHeight();

       return mH;
   }

   public Rect getBound(){

       return new Rect( );

   }

   public  int getradius(){
    return mR ;
   }


}
</code></pre>

<p>And below here is the class for the activity</p>

<pre><code>package droid.pkg;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import droid.pkg.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
import android.graphics.BitmapFactory;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorManager;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.SensorEventListener;

public class TiltBallActivity extends Activity {

    BallView mBallView = null;
    Handler RedrawHandler = new Handler(); //so redraw occurs in main thread
    Timer mTmr = null;
    TimerTask mTsk = null;
    Platform p,p2,p3,p4 ;
    //Level level ;
    int lev ;
    ArrayList&lt;Platform&gt; levelbarriers;

    int mScrWidth, mScrHeight,mz,mx;
    android.graphics.PointF mBallPos, mBallSpd ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE); //hide title bar
        getWindow().setFlags(0xFFFFFFFF,
                LayoutParams.FLAG_FULLSCREEN|LayoutParams.FLAG_KEEP_SCREEN_ON);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //create pointer to main screen
        final FrameLayout mainView = (android.widget.FrameLayout) findViewById(R.id.main_view);
levelbarriers = new ArrayList&lt;Platform&gt;() ;
        //get screen dimensions


        Display display = getWindowManager().getDefaultDisplay();  
        mScrWidth = display.getWidth(); 
        mScrHeight = display.getHeight();
        mBallPos = new android.graphics.PointF();
        mBallSpd = new android.graphics.PointF();

         level(0) ;

        //create variables for ball position and speed
        mBallPos.x = mScrWidth/2; 
        mBallPos.y = mScrHeight/2; 
        mBallSpd.x = 0;
        mBallSpd.y = 0; 

        //create initial ball
        mBallView = new BallView(this);

        mainView.addView(mBallView); //add ball to main screen
        for(int i = 0 ;i &lt; levelbarriers.size();i++){

            mainView.addView(levelbarriers.get(i));
        }

        mBallView.invalidate(); //call onDraw in BallView
      for(int i = 0 ;i &lt; levelbarriers.size();i++){

            levelbarriers.get(i).invalidate();
        }

        //listener for accelerometer, use anonymous class for simplicity
        ((SensorManager)getSystemService(Context.SENSOR_SERVICE)).registerListener(
            new SensorEventListener() {    
                @Override  
                public void onSensorChanged(SensorEvent event) {  
                    //set ball speed based on phone tilt (ignore Z axis)
                    mBallSpd.x = -event.values[0];
                    mBallSpd.y = event.values[1];
                    //timer event will redraw ball
                }
                @Override  
                public void onAccuracyChanged(Sensor sensor, int accuracy) {} //ignore this event
            },
            ((SensorManager)getSystemService(Context.SENSOR_SERVICE))
            .getSensorList(Sensor.TYPE_ACCELEROMETER).get(0), SensorManager.SENSOR_DELAY_NORMAL);

        //listener for touch event 
        }        
    //listener for menu button on phone
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("Exit"); //only one menu item
        return super.onCreateOptionsMenu(menu);
    }

    //listener for menu item clicked
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection    
        if (item.getTitle() == "Exit") //user clicked Exit
            finish(); //will call onPause
        return super.onOptionsItemSelected(item);    
    }

    //For state flow see http://developer.android.com/reference/android/app/Activity.html
    @Override
    public void onPause() //app moved to background, stop background threads
    {
        mTmr.cancel(); //kill\release timer (our only background thread)
        mTmr = null;
        mTsk = null;
        super.onPause();
    }

    @Override
    public void onResume() //app moved to foreground (also occurs at app startup)
    {
        //create timer to move ball to new position

        mTmr = new Timer(); 
        mTsk = new TimerTask() {
            public void run() {
                //if debugging with external device, 
                //  a cat log viewer will be needed on the device
                android.util.Log.d(
                    "TiltBall","Timer Hit - " + mBallPos.x + ":" + mBallPos.y);
                //move ball based on current speed
                mBallPos.x += mBallSpd.x;
                mBallPos.y += mBallSpd.y;

                if (mBallPos.x &gt; mScrWidth){
                    mBallPos.x=mScrWidth-mBallView.getradius();
                }
                if (mBallPos.y &gt; mScrHeight){
                    mBallPos.y= mScrHeight -mBallView.getradius();
                }
                if (mBallPos.x &lt; 0){
                    mBallPos.x=0 + mBallView.getradius();
                }
                if (mBallPos.y &lt; 0) {
                  mBallPos.y = 0 + mBallView.getradius();
                }


                //update ball class instance
                mBallView.mX = mBallPos.x;
                mBallView.mY = mBallPos.y;
                //redraw ball. Must run in background thread to prevent thread lock.
                RedrawHandler.post(new Runnable() {
                    public void run() { 
                       mBallView.invalidate();                       

                       for(int i = 0 ;i &lt; levelbarriers.size();i++){

                            levelbarriers.get(i).invalidate();
                        }

                  }});
            }}; // TimerTask

        mTmr.schedule(mTsk,10,10); //start timer
        super.onResume();
    } // onResume

    @Override
    public void onDestroy() //main thread stopped
    {
        super.onDestroy();
        System.runFinalizersOnExit(true); //wait for threads to exit before clearing app
        android.os.Process.killProcess(android.os.Process.myPid());  //remove app from memory 
    }

    //listener for config change. 
    //This is called when user tilts phone enough to trigger landscape view
    //we want our app to stay in portrait view, so bypass event 
    @Override 
    public void onConfigurationChanged(Configuration newConfig)
    {
       super.onConfigurationChanged(newConfig);
    }

public  void level(int a ){
    lev = a ;
    if(lev == 0){
        mx = 50 ;
        mz = 50 ;
        //ArrayList&lt;Platform&gt; levelbarriers = new ArrayList&lt;Platform&gt;();
        levelbarriers.add(new Platform(this,mx,mz, BitmapFactory.decodeResource(getResources(),R.drawable.level1_big3)));
        levelbarriers.add(new Platform(this,mScrWidth-130,mz + 100, BitmapFactory.decodeResource(getResources(),R.drawable.level1_small)));
        levelbarriers.add(new Platform(this,mScrWidth,mz + 200, BitmapFactory.decodeResource(getResources(),R.drawable.level1_small2)));
        levelbarriers.add(new Platform(this,mScrWidth-70,mz + 200, BitmapFactory.decodeResource(getResources(),R.drawable.level1_small2)));
        levelbarriers.add(new Platform(this,mScrWidth-70,mz + 200, BitmapFactory.decodeResource(getResources(),R.drawable.level1_small)));


    }
    }
}
</code></pre>

<p>Any Help is greatly appreciated as i am a brand new android developer and would love to get this working. Please explain in detail where the problem is, and if you can, please supply example code to fix it.</p>

<p>My problem is, the screen is exactly how i want it, a green background(done in the xml) with 3 blocks(inserted by the last few lines of code in the second block) and a football, what should be happening is, the ball should move in the direction i tilt the phone, but the ball remains where it is and no motion happenes.</p>

<p>The code used was working when i wasnt using a Bitmap, when i used the onDraw to draw a circle that moved. I dont understand what changed that the Bitmap wont move and the basic circle would.</p>

<p>Regards</p>

<p>A</p>
