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

Closed
ajeecai opened this issue Jan 8, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@ajeecai
Copy link

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?

Yes

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 GORACE=
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_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-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 (
"Java/android/databinding/DataBindingUtil"
"Java/android/os"
"Java/android/net/VpnService"
gonet "Java/android/net"
gointent "Java/android/content/Intent"

"Java/android/support/v7/app"
gopkg "Java/reverse"
rlayout "Java/reverse/R/layout"
"Java/reverse/databinding"
"Java/reverse/databinding/ActivityMainBinding"
)

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

}

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

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:

startService(getServiceIntent().setAction(ToyVpnService.ACTION_DISCONNECT));

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

Thanks

@ALTree

This comment has been minimized.

Copy link
Member

commented Jan 8, 2018

Hi,

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.
You can’t perform that action at this time.