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.
3 videos • 2 quizzes • 1 code challenge
-
Play
Preview
Adding a Shake Detector
8 minutes 34 seconds
-
ABC
Preview
Quiz: System Services and the Accelerometer
5 questions
-
Play
Preview
The Activity Lifecycle
10 minutes 3 seconds
-
Code Challenge
Preview
Code Challenge: The Activity Lifecycle
5 objectives
-
Play
Preview
Running an App on a Device
4 minutes 26 seconds
-
ABC
Preview
Quiz: Running an App on a Device
5 questions
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.