This is a creation in Article, where the information may have evolved or changed.
Life cycle events are events that are triggered when a state switches from one phase to another. So we can see lifecycle. The Event is defined as follows:
There are four phases in the life cycle:
Lifecycle. Stagedead, lifecycle. Stagealive, lifecycle. Stagevisible, lifecycle. stagefocused, specifically defined as:
A code that can be used to analyze the sequence of individual events:
+build Darwin Linux
Package Main
Import "Log"
Import "Golang.org/x/mobile/app"
Import "Golang.org/x/mobile/event/lifecycle"
Import "Golang.org/x/mobile/event/paint"
Func Main () {
App. Main (func (a app). APP) {
Each posible lyfecycle stage
For e: = Range a.events () {
When an events come ' s
Switch e: = A.filter (E). (type) {
Case lifecycle. Event:
Log. Println (E.from, "--", e.to)
Case Paint. Event:
If it ' s a paint event, log it
If e.external {
Log. PRINTLN ("Paint external")
} else {
Log. PRINTLN ("Paint internal")
}
A.publish ()
}
}
})
}
SOURCE from: HTTPS://DEV.SNIP2CODE.COM/SNIPPET/789859/SIMPLE-APP-FOR-GOMOBILE--THAT-LOGS-LIFEC
The business process on a Mac notebook is as follows:
The life cycle process of testing under Android is as follows:
These event conversions are known as follows:
As can be seen from the above, Android under the launch of our application, directly from the Stagedead to the stagefocused, we will not be in stagevisible and stagealive to do some code?
The solution is to use the crosses function, which is used to determine if a stage has passed.
Why is this, in the description of the Stage, in the simple case, this is a size enumeration, so that you can determine whether a process.
Our code for using it is as follows:
It is divided into two types, forward and reverse. The corresponding upper and lower is entered the display state, or left the display state.
So the sequence of events is as follows, except that you can quickly skip a few processes, and use the crosses function to determine if a step has been skipped.
Resources:
Http://klabgames.tech.blog.jp.klab.com/archives/1038277477.html