Пример #1
0
            public void OnServiceConnected(ComponentName name, IBinder service)
            {
                var demoServiceBinder = service as DemoServiceBinder;

                if (demoServiceBinder != null)
                {
                    _activity._binder  = demoServiceBinder;
                    _activity._isBound = true;
                    _binder            = demoServiceBinder;
                }
            }
Пример #2
0
            public void OnServiceConnected(ComponentName name, IBinder service)
            {
                var demoServiceBinder = service as DemoServiceBinder;

                if (demoServiceBinder != null)
                {
                    activity.binder  = demoServiceBinder;
                    activity.isBound = true;

                    // keep instance for preservation across configuration changes
                    this.binder = demoServiceBinder;
                }
            }
Пример #3
0
        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;
		}
Пример #5
0
        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;
            }
        }
		public override Android.OS.IBinder OnBind (Android.Content.Intent intent)
		{
			binder = new DemoServiceBinder (this);
			return binder;
        }
Пример #7
0
 public override IBinder OnBind(Intent intent)
 {
     _binder = new DemoServiceBinder(this);
     return(_binder);
 }
			public void OnServiceConnected (ComponentName name, IBinder service)
			{
				var demoServiceBinder = service as DemoServiceBinder;
				
				if (demoServiceBinder != null) {
					activity.binder = demoServiceBinder;
					activity.isBound = true;

					// keep instance for preservation across configuration changes
					this.binder = demoServiceBinder;
				}
			}
Пример #9
0
 public override Android.OS.IBinder OnBind(Android.Content.Intent intent)
 {
     binder = new DemoServiceBinder(this);
     return(binder);
 }