Skip to content

Instantly share code, notes, and snippets.

@BrianCraig
Created November 11, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianCraig/bb2bb411a202b35c1a88 to your computer and use it in GitHub Desktop.
Save BrianCraig/bb2bb411a202b35c1a88 to your computer and use it in GitHub Desktop.
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