Most of the techniques for managing data in memory in Java don’t change in Android. You’re using basic Java architectures. When you want to work with a value only within a method, define a variable that’s local to that method. To persist a value for the lifetime of an Activity, declare it as an instance field of the Activity class. To make values available to the rest of the application, set a field’s access identifier to public. These basic patterns are common to all Java applications, regardless of platform or application framework.
- View Offline
- [Voiceover] Most of the techniques for managing…data in memory in Java don't change in Android.…You're using basic Java architectures.…When you want to work with a value only within a method,…define a variable that's local to that method.…To persist a value for the lifetime of an activity,…declare it as an instance field of the activity class.…To make values available to the rest of the application,…set a field's access identifier to public,…and so on.…These basic patterns are common to all Java applications…regardless of platform or application framework…but there are some important things to be aware of,…particularly how variable values are affected…by the activity lifecycle.…
Instance variables are lost when their parent objects…are destroyed.…These values taken together are known in Android…as instance state and Android gives you a very easy way…to save and restore that state when activities are destroyed…or recreated.…I'll show you some examples here.…In this project, InstanceData, I'll go first…to my XML layout file, activity_main.xml…
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