Skip to content

Instantly share code, notes, and snippets.

@BrianCraig

BrianCraig/main.go

Created Nov 11, 2015
Embed
What would you like to do?
Simple App for GoMobile, that logs lifecycle and paints events for debugging purposes
// +build darwin linux
package main
import "fmt"
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
stages := []lifecycle.Stage{lifecycle.StageDead, lifecycle.StageAlive, lifecycle.StageVisible, lifecycle.StageFocused}
for e := range a.Events() {
// when an events come's
switch e := a.Filter(e).(type) {
case lifecycle.Event:
// if it's a lifecycle status event
for _, stage := range stages {
// log each state
fmt.Println(stage, e.Crosses(stage))
}
case paint.Event:
// if it's a paint event, log it
if e.External {
fmt.Println("paint external")
} else {
fmt.Println("paint internal")
}
a.Publish()
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment