I have a Xamarin.forms application which use a Android Service.
The MainPage calls a specific Class in Android part via Dependency Service
and this class binds the Service. The Application Context is passed by the 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;
}
Everything is fine, but when the method OnServiceConnected() is called all my member variable are null.
Anybody an Idea ?
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();
}
}
}