It’s important to refactor and keep your code clean, as you’ve learned in this chapter. Android gives you a way to lay out child views in relation to each other and to their parent view group, and adding event handlers to your code lets your app react to button clicks.
Looking further into the activity lifecycle identifies a few issues with the application you’re building. To fix these issues, you implement simple threading by using the Runnable interface and the Handler class. (Remember it’s important to not hold up the main thread of the UI, or you’ll get the dreaded Application Not Responding dialog box.) You can display a new activity by creating an intent and calling startActivity.
To store your application’s state, you can create a data model and extend the Application class. In this data model, you store a simple user preference to control whether or not the device will vibrate.