Brief introduction
Today's mobile devices are incredibly powerful, much more powerful than many developers use to write their first program. Therefore, it is easy to forget that mobile devices still belong to a limited resource environment. When you develop mobile applications, you must never forget the limitations of the environment in which you run your application. Especially when an application competes with other applications for system resources-some of these applications are more important to the user's day-to-day behavior than your application.
One way to ensure that your application is popular is to ensure that it saves system resources. In Android, the mechanism for using and maintaining system resources is the activity class. The more you understand the lifecycle of this basic class (which is very similar to the Java Servlet), the stronger the ability to adjust the resource usage and performance of the Android mobile application.
We'll start with a quick understanding of the activity class lifecycle. With a demo of the example application, you'll learn how to handle each phase of the Android application lifecycle. After mastering the principles of these methods working together, you can intelligently use system resources. Then update the navigation system for the demo application and use the action icon instead of the menu button to achieve user interaction. Icons are very standard in the mobile application UI, and newer Android devices (version 4.2.2 and higher versions) have deprecated the option menu and instead use the action bar. Mastering how to integrate these features with your Android mobile application will benefit you immensely!
Related articles:
Mobile technology for the masses: Android introduction
Http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/201310/37779.htm
Mobile technology for the masses: coding for gestures in Android
Http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/201310/37797.htm
Activity class life cycle
The life cycle of an activity directly corresponds to the lifecycle of the Android mobile application. When a user interacts with an application or a device running an application, the Android platform performs a callback on the activity instance. When the user launches the application, the initial activity executes a defined lifecycle. When an application goes backstage, it executes a different phase of the lifecycle and executes another phase when the application shuts down. Figure 1 shows the Android activity lifecycle for each interaction phase.
Figure 1. Android's Activity lifecycle
The Android Mobile application lifecycle consists of four phases:
Start
pausing and resuming
Stop and reboot
Destroyed
The following sections describe each phase and its callback methods (which can be implemented within the activity instance).
Initiation in the Activity lifecycle
Demo Application
If you've been following this series of articles, you've created your own demo application in the first and second articles of this series. If you do not have a demo application, it is recommended that you create one before continuing. Alternatively, you can copy my own Git library for the overheard Word demo application.
In the previous article, you have used a callback method that corresponds to the initiating activity, that is, onCreate. You may also be familiar with OnStart and Onresume, and these two methods will be invoked at startup. These methods are now considered in the context of the activity lifecycle.
In the Eclipse Android development environment, choose override/implement Methods ... option, you can easily override the method, as shown in Figure 2.
Figure 2. Overriding the activity lifecycle callback method