Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: How does reverse binding New a class? #23371

ajeecai opened this issue Jan 8, 2018 · 1 comment

x/mobile: How does reverse binding New a class? #23371

ajeecai opened this issue Jan 8, 2018 · 1 comment


Copy link

@ajeecai ajeecai commented Jan 8, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 windows/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

What did you do?

Want to write a simple Anroid VPN app with reverse binding. I did a quick test based on the reverse example.

So I make an attempt for try as

package reverse

import (
gonet "Java/android/net"
gointent "Java/android/content/Intent"

gopkg "Java/reverse"
rlayout "Java/reverse/R/layout"

type MainActivity struct {
binding databinding.ActivityMainBinding
func (a *MainActivity) OnCreate(this gopkg.MainActivity, b os.Bundle) {
db := DataBindingUtil.SetContentView(this, rlayout.Activity_main)
a.binding = ActivityMainBinding.Cast(db)
a.StartService(gointent.New(this, gonet.VpnService))


func (a *MainActivity) OnDestroy(this gopkg.MainActivity) {
a.binding = nil // break reference cycle

func (a *MainActivity) GetLabel() string {
return "Hello from Go!"

main change is VpnService.Prepare(this) and a.StartService(gointent.New(this, gonet.VpnService)), which comes from ToyVPN:


private Intent getServiceIntent() {
return new Intent(this, ToyVpnService.class);

What did you expect to see?

Compile OK

What did you see instead?

..\reverse\reverse.go:34:29: type net.VpnService is not an expression.
Change to a.StartService(gointent.New(this, gonet.VpnService.Class)) also doesn't help

For reverse binding, I mainly refer to #16876 @eliasnaur


Copy link

@ALTree ALTree commented Jan 8, 2018


the Go project does not use its bug tracker for general discussion or asking questions about the language. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!

Closing, since it appears you are not reporting a Go bug.

@ALTree ALTree closed this Jan 8, 2018
@mikioh mikioh changed the title How does reverse binding New a class? x/mobile: How does reverse binding New a class? Jan 13, 2018
@golang golang locked and limited conversation to collaborators Jan 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.