protected override void OnStart () { base.OnStart (); var demoServiceIntent = new Intent ("com.xamarin.DemoService"); demoServiceConnection = new DemoServiceConnection (this); BindService (demoServiceIntent, demoServiceConnection, Bind.AutoCreate); }
protected override void OnStart() { base.OnStart(); var demoServiceIntent = new Intent("com.xamarin.DemoMessengerService"); demoServiceConnection = new DemoServiceConnection(this); BindService(demoServiceIntent, demoServiceConnection, Bind.AutoCreate); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); textViewStatus = FindViewById <TextView>(Resource.Id.textViewStatus); textViewMessage = FindViewById <TextView>(Resource.Id.textViewMessage); buttonStart = FindViewById <Button>(Resource.Id.buttonStart); textViewMessage.Visibility = ViewStates.Gone; buttonStart.Click += delegate { Intent demoServiceIntent = new Intent("MrGo.SMS.Service"); demoServiceConnection = new DemoServiceConnection(this); this.ApplicationContext.BindService(demoServiceIntent, demoServiceConnection, Bind.AutoCreate); StartService(new Intent("MrGo.SMS.Service")); textViewStatus.Text = "MrGO SMS Service has started"; }; buttonStop = FindViewById <Button>(Resource.Id.buttonStop); buttonStop.Click += delegate { //StopService (new Intent (this, typeof(DemoService))); binder.GetDemoService().startThread = false; StopService(new Intent("MrGo.SMS.Service")); textViewStatus.Text = "MrGO SMS Service has stoped"; }; //Button callService = FindViewById<Button>(Resource.Id.callService); //callService.Click += delegate { // if (isBound) // { // RunOnUiThread(() => { // string text = binder.GetDemoService().GetText(); // Console.WriteLine("{0} returned from DemoService", text); // } // ); // } //}; // restore from connection there was a configuration change, such as a device rotation //demoServiceConnection = LastNonConfigurationInstance as DemoServiceConnection; //if (demoServiceConnection != null) // binder = demoServiceConnection.Binder; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); var start = FindViewById <Button> (Resource.Id.startService); start.Click += delegate { //StartService (new Intent (this, typeof(DemoService))); StartService(new Intent("com.xamarin.DemoService")); }; var stop = FindViewById <Button> (Resource.Id.stopService); stop.Click += delegate { //StopService (new Intent (this, typeof(DemoService))); StopService(new Intent("com.xamarin.DemoService")); }; var callService = FindViewById <Button> (Resource.Id.callService); callService.Click += delegate { if (isBound) { RunOnUiThread(() => { string text = binder.GetDemoService().GetText(); Console.WriteLine("{0} returned from DemoService", text); } ); } }; // restore from connection there was a configuration change, such as a device rotation demoServiceConnection = LastNonConfigurationInstance as DemoServiceConnection; if (demoServiceConnection != null) { binder = demoServiceConnection.Binder; } }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); var start = FindViewById<Button> (Resource.Id.startService); start.Click += delegate { //StartService (new Intent (this, typeof(DemoService))); StartService (new Intent ("com.xamarin.DemoService")); }; var stop = FindViewById<Button> (Resource.Id.stopService); stop.Click += delegate { //StopService (new Intent (this, typeof(DemoService))); StopService (new Intent ("com.xamarin.DemoService")); }; var callService = FindViewById<Button> (Resource.Id.callService); callService.Click += delegate { if (isBound) { RunOnUiThread (() => { string text = binder.GetDemoService ().GetText (); Console.WriteLine ("{0} returned from DemoService", text); } ); } }; // restore from connection there was a configuration change, such as a device rotation demoServiceConnection = LastNonConfigurationInstance as DemoServiceConnection; if (demoServiceConnection != null) binder = demoServiceConnection.Binder; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); var buttonStart = FindViewById <Button> (Resource.Id.startService); buttonStart.Click += (s, e) => { StartService(new Intent("com.xamarin.DemoService")); }; var buttonStop = FindViewById <Button> (Resource.Id.stopService); buttonStop.Click += (s, e) => { var b = StopService(new Intent("com.xamarin.DemoService")); }; var buttonCallService = FindViewById <Button> (Resource.Id.callService); buttonCallService.Click += (s, e) => { if (_isBound) { RunOnUiThread(() => { var text = _binder.GetDemoService().GetText(); Console.WriteLine("{0} returned from DemoService", text); }); } }; _demoServiceConnection = LastNonConfigurationInstance as DemoServiceConnection; if (_demoServiceConnection != null) { _binder = _demoServiceConnection.Binder; } }