Shaking Things Up

Shaking Things Up

We want our app to be fun and engaging, so in this stage we'll show you how to add code to detect when you shake your phone. Then we'll show how to display an answer as a result of that shake. And since shaking involves an actual phone, we'll show you how to run your app on a real device.

Extra Credit

Super Shake!

Change some of the parameters in the ShakeDetector class to see how it affects shaking your phone. What makes it harder to trigger a "Shake"? What makes it easier?

Take a Peek

The "Shake" event is finalized in the onSensorChanged() method in the ShakeDetector class. Our listener is notified with the line mShakeListener.onShake();. After this line, add a Log statement or two in the class to log some of the ShakeDetector variables like startTime, elapsedTime, and moveCount.