-2

i want to navigate pages using shake command but its getting errors,So what i missed in my code.I cannot understand what is Accelerometer.Here my code.

public class ACTIVITY extends Activity { /** Called when the activity is first created. */

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

            SensorManager mSensorManager;

            ShakeEvent mSensorListener;

            mSensorListener = new ShakeEvent();
            mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                SensorManager.SENSOR_DELAY_UI);


            mSensorListener.setOnShakeListener(new ShakeEvent.OnShakeListener() {

              public void onShake() {
                  Intent i = new Intent(shake.this, NEWACTIVITY.class);
                  startActivity(i);
              }
            });
        }}

Thanx for helping.

samadi
  • 19
  • 1
  • 3

1 Answers1

0

You said that your activity is called "ACTIVITY". But in your onShake method you create an Intent with first argument "shake.this". That doesn't make any sense, because your OnShakeListener is not nested in a class called "shake" (and furthermore that first argument must be a Context object!). You need to write the following instead:

          public void onShake() {
              Intent i = new Intent(ACTIVITY.this, NEWACTIVITY.class);
              startActivity(i);
          }
tiguchi
  • 5,392
  • 1
  • 33
  • 39