There isn’t a single required architecture for organizing Android code, but there are some recommended strategies that work well, both for app performance and long-term code maintenance. One of these strategies is to organize commonly used code in static methods, and then to keep these methods in their own separate classes. In this example, you'll find a simple way to centralize some very common code: displaying a message in a TextView widget.
- [Voiceover] There isn't a single required architecture…for organizing Java code in Android.…But there are some recommended strategies…that work well…both for app performance…and long-term code maintanence.…One of these strategies is to organize commonly used code…in static methods.…And then to keep these methods in their own…separate classes.…I'll describe a simple way to centralize some…very common code in this project…"method libraries".…I'll display a message in a text view widget…and then I'll modify that code…so a message appears in the app itself…and in Android Studio's logcat window…at the same time.…
I'll start by creating a new package in my app.…In the project window I'll go to my base package.…Right click.…And choose "new package".…And I'll name the new package, "utilities".…Then, I'll right-click on the new package…and I'll choose "new", "Java Class".…And I'll name the new class, "activity helper".…So the helper class will contain static methods…that help me manage my activities.…
I'll get rid of the automatically generated comment…
Watch these Java tutorials to learn smarter, more efficient methods for Android app development.
- Preparing the development environment
- Packaging and running Android apps
- Optimizing Java code for Android
- Implementing event handler interfaces
- Defining custom callback methods
- Working with the Android SDK's Java packages
- Storing data
- Reading text files
- Parsing JSON and XML data
- Managing device sensors
- Playing audio