"> ">
Download presentation
Presentation is loading. Please wait.
1
What's Happening Today Working with Images
What does this mean for the UI? What does this mean for resources? What about shaking things up? What happens when you slip the schedule? … ...
2
Android Sensors Sensors come in several flavors We'll only use accelerometer in examples Use is similar to other Android features Register Sensor in AndroidManifest.XML <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
3
Registering/Using Sensor
Typical of Observable Design Pattern AKA Publish Subscribe Observer is registered with Observable, which typically could have several observers See code for getting SensorManager and the sensor/accelerometer RecyclerViewActivity
4
Create SensorEventListener
This is the Observer in design pattern Standard Android, we use ShakeDetector and implement the Interface Notice nested Interface in ShakeDetector Register a listener with this detector, what is doing the listening? Activity indirectly
5
Activity Life Cycle Code in onResume and onPause to handle the SensorManager and ShakeDetector What might happen in onPause if not unregistered? What does "listening" do? What's important in App management? Sensor can continue to collect data, but not be able to do anything with data
6
Android aside in ShakeDetector
Notice float values in SensorManager What about value returned Math.sqrt? Is there an issue between float and double? Documentation for Android says … What are the key take-aways on that page?
7
Code to handle shakes … Anonymous inner class to implement the OnShakeListener interface Expedient (?) way to call a method in the Activity, note the local method Take advantage of RecylerView Adapter Attention to all components in Adapter, e.g., The ViewHolder What happens in method updateList ?
8
Handling ClickEvents Another example of Observer pattern
How does this happen with CardView? Examine RecyclerView.ViewHolder … Is this bound to position? How to test? What if we wanted to do more with click, not simply create a Toast How do we notify another Activity?
9
What is an Intent? Start one activity from another Start a service
Launch when something happens Start a service Camera, phone, music player Broadcast message (app or service) Apps can respond
10
Intent basics Create Intent, provide Activity class
Launch with method startActivity Store "extras" in intent to pass information from one activity to another Can also start activity and "wait" for result See these examples later
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.