【发布时间】:2017-05-29 09:02:20
【问题描述】:
我有一个使用 Android 服务的 Xamarin.forms 应用程序。
MainPage 通过依赖服务调用 Android 部分中的特定类
并且这个类绑定了服务。应用程序上下文由 MainPage 传递。
public bool BindService() {
Intent intent = new Intent("com.plustek.service.plkscan.IPlkScanService");
this._scanServiceConnection = new ServiceConnection(this, this._scanCallBack, this._systemCallBack);
bool serviceBoundSuccess = this.Context.BindService(intent, this._scanServiceConnection, Bind.AutoCreate);
if (serviceBoundSuccess) {
return true;
}
return false;
}
一切都很好,但是当调用 OnServiceConnected() 方法时,我的所有成员变量都为空。
任何人的想法?
internal class ServiceConnection : Java.Lang.Object, IServiceConnection {
public IPlkScanService PlcScanService { get; private set; }
private PlkSystemCallBack _plkSystemCallBack;
private PlkScanCallBack _plkScanCallBack;
private PlustecDocumentScanner _plustecDocumentScanner;
public ServiceConnection(PlustecDocumentScanner plustecDocumentScanner, PlkScanCallBack plkScanCallBack, PlkSystemCallBack plkSystemCallBack) : this(){
this._plkScanCallBack = plkScanCallBack;
this._plkSystemCallBack = plkSystemCallBack;
this._plustecDocumentScanner = plustecDocumentScanner;
}
public ServiceConnection(IntPtr dfref, JniHandleOwnership asdf) {
}
public void OnServiceConnected(ComponentName name, IBinder service) {
this.PlcScanService = PlkScanServiceStub.AsInterface(service);
try {
this.PlcScanService.InitService(this._plkScanCallBack);
this.PlcScanService.RegisterSystemCallBack(this._plkSystemCallBack);
this.PlcScanService.MountScannerDevice();
this._plustecDocumentScanner.PlcScanService = this.PlcScanService;
} catch (RemoteException e) {
e.PrintStackTrace();
}
}
}
【问题讨论】:
标签: android xamarin xamarin.android