Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (retired 2014) Shaking Things Up The Activity Lifecycle

Ricky Sparks
Ricky Sparks
22,249 Points

whats wrong with my java code?

package com.example;

import android.os.Bundle; import android.view.View; import android.hardware.Sensor; import android.hardware.SensorManager;

public class MainActivity extends Activity {

public static String aString;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private ShakeDetector mShakeDetector;

public void onCreate(Bundle savedInstanceState) {
super.onCreate ( savedInstanceState);

    setContentView(R.layout.activity_main); 

    aString = "This variable is set AFTER the 'otherString' variable in Activity";

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mShakeDetector = new ShakeDetector();
}

public void onPause() {
super.onPause();
unregisterListener(ShakeDetector );
}

public void onResume() {
    super.onResume();
    mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}

}

Ricky Sparks
Ricky Sparks
22,249 Points

i believe its something in here

public void onPause() { super.onPause(); unregisterListener(ShakeDetector ); }

Ben Junya
Ben Junya
12,365 Points

Hey Ricky,

It's really difficult for me to help you out unless I know exactly what's happening. Is the program crashing? Is it doing something it's not supposed to do? We don't know.

Also, if you can list your StackTrace from Logcat, I would be able to help you out more.

Ricky Sparks
Ricky Sparks
22,249 Points

This is a code challenge.

Ben Junya
Ben Junya
12,365 Points

What is the challenge asking you to do? What's the instructions or objective?

1 Answer

Ricky Sparks
Ricky Sparks
22,249 Points

Thanks for the responses but i figured the challenge out :D