Lifecycle of [Android] activity
Override the following methods in mainactivity:
Print the log in these methods. In order to facilitate viewing, add a system.out in the filter to filter
onCreate()
onDestory()
onPause()
onResume()
onStart()
onStop()
When an activity is opened and closed for the first time, the call sequence oncreate = = > OnStart = = > onresume = = > Close = = > onpause = = > onstop = = > ondestroy
Open the process of the second activity. The status of the first interface oncreate = = > OnStart = = > onresume = = > open the second activity = = > onpause = = > onstop = = > close the second = = > OnStart = = > onresume = = > close the first = = > onpause = = > onstop = = > ondestroy
Test to get focus and lose focus, create a third activity and modify the style. There is an apptheme widget in the preview interface, where theme has a dialog box option. In the list file, add theme attributes to the < activity / > node
Set the theme Android: theme = "@ Android: style / theme. Dialog" the style of the system R file and the style of the dialog box
Click the button to open the activity. At this time, the first interface will call the onpause method and lose focus
Click the blank part, and the first interface will get the focus, onresume method
The life cycle corresponds in pairs and can be divided into three parts: complete life cycle, visual life cycle and foreground life cycle. Clicking the back button will destroy the activity
Life cycle usage scenarios, data persistence, such as writing a microblog, when the user accidentally presses the back button, the activity will call the ondestroy method, and we can save the data to a file or sp
When the interface is newly visible, the OnStart method will be called. We can update the interface or change the business logic
For example, when you jump to the activity and ask the user to configure something, the user clicks return without configuring it. At this time, we can write the code for detecting the network into the OnStart () method, so that the user experience is not good. You can use the dialog box
Get the alertdialog.builder object through new Builder (context). Parameter: Context
Call the settitle () method of the builder object to set the title
Call the setMessage () method of the builder object to set the content
Call the setpositivebutton (text, listener) method of the builder object, set the OK button, parameters: text, onclicklistener interface object, directly new through the anonymous inner class, and override the onclick () method
Call the create () method of the builder object, call the show () method, and create and display it