Activities in Android go through a lifecycle. A set of stages, as they appear and disappear on the device. As that activity enters each state, a method is called that's a member of the activity. You can controls what happens in each stage by overriding these methods in your Java code. I'll describe each method, the state it's related to, and what you can do with your custom lifecycle code.
- Java developers who are working in Android…should have a good understanding on inheritance.…How each class can extend and inherit…the capabilities of a super class.…This is especially important when you're working…with activities and their lifecycle methods.…I'm working with a project named Callbacks now.…I'll open the file MainActivity.java.…This project is a copy of my code runner app.…I have the onCreate method…which is almost always present in an activity class…and it's executing a bit of code…calling it super classes version of onCreate…setting the content view to a layout file…and then there are a few…custom lines of code there as well.…
It's important to understand the…inherent hierarchy of the activity class.…My main activity class extends AppCompatActivity…and I'll hold down the command key on Mac…or the control key on windows…and click the name of the super class.…That takes me to the class declaration.…This class also has an onCreate method…and if I go back to MainActivity…I'll see that I'm calling the super classes version first…
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