Go Mobile life cycle events

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.