How to change Activity views from Service???

AliciaFifiruchiAliciaFifiruchi USMember
edited April 2015 in Xamarin.Android

I have an application that get/send data from/to a remote DB on internet.
I need to get my application working in background mode, then I supose that i have to put all the send/get remote data in a service, then I need to change some values like some button visibilities or a checkbox.
My question is how to pass objects from my activity/layout to my service so I can make changes to my layout/activity???

I have this in my code:
[Service]
public class service_test : Service
{
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
dostuff();
return base.OnStartCommand(intent, flags, startId);

                }

                private void dostuff()
                {
                      LayoutInflater infl = (LayoutInflater) GetSystemService(LayoutInflaterService);
                      View layView = infl.Inflate(Resource.Layout.UserArrivedServiceNoData, null);
                      Button cancelButton = layView.FindViewById<Button>(Resource.Id.btnCancelND);
                      cancelButton.Visibility = ViewStates.Invisible;
                      Chronometer chro = layView.FindViewById<Chronometer>(Resource.Id.chronometer2);
                      chro.Start();

                      Toast.MakeText(this, "Button is invisible", ToastLength.Long).Show();                  

                }

And in some button of my layout i have this

        var intservice = new Intent(this, typeof (service_test));
                StartService(intservice);

When I click the button it only sends me the toast, but it doesnt make the button invisible nor starts the chronometer

I dont know if i have to acces from my service to the layout like i tried, or I have to send from the Activity to the service what i want to change.

I can't find any information about this, all the tutorials I am finding are of simple services that doesn't do something like that.

Could someone help me with this please??

Sign In or Register to comment.