Auto Refresh in Xamarin application.

Asked

Viewed 498 times

3

I am developing an application that in the main screen will have some buttons, and these buttons access a URL sending commands on and off all this through Httpclient and persisting all this information.

I have the following scenario:

  • I have 3 buttons all with status off.
  • User 1 with your mobile click on the button 3 that accesses the server and persists this information to
  • The Mobile User 2 must from time to time know the status of these buttons
  • Both Users can use the on and off buttons feature.

How to make Activity from time to time perform this update, I tried to do the example below but succeeded.

I stand by.

Handler handler = new Handler();

private void doTheAutoRefresh()
        {
            handler.postDelayed(new Runnable() {
        @Override
        public void run()
        {
            // Write code for your refresh logic
            doTheAutoRefresh();
        }
    }, 5000);
}

2 answers

2


Friends I solved the problem and to better detail and share what I could do, I had to answer my own question and not only comment

I imported the library: using Android.OS;

I initialized Handler: Handler Handler = new Handler();

I have a function that initializes the buttons that are on the screen:

InicializaButtons()
{
    //Realiza os procedimentos de inicialização dos botões

    //Esta função não só inicializa, mas é usada varias vezes no decorrer da utilização do software, quando necessário.


    //Aqui esta a mágica do negócio
    //De 5 em 5 segundos estou chamando a função InicializaButtons
    handler.PostDelayed(InicializaButtons, 5000);
}

I hope to help many people with this solution.

I’m testing here to see the performance of the device, the already seen we are messing with mobile devices with hardware most of the time a little weak.

0

The solution of the ultialization of the Android.OS library probably solves in cases where Xamarin.Droid is used, but since the question raised is about Xamarin.Forms to execute a task in a given interval it is necessary to use Timers, follows a test link to see the behavior of a timer in Xamarin.Forms. Test timer code in Xamarin.Forms

  • Jorge Carlos Guedert with the Handler Solution is satisfactory, and I already see as solved this post, and through the solution I implanted Handler, I am using beyond the expected perfect, and the best without flaws, and most importantly the system is working without overloading the mobile device.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.