Question:
I'm developing an application that on 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 off status.
- User 1 with his cell phone clicks on button 3 that accesses the server and keeps this information on
- User 2 with cell phone should from time to time know the status of these buttons
- Both Users will be able to use the on and off feature of the buttons.
How to make the activity from time to time perform this update, I tried to do the example below but got success.
I'm waiting.
Handler handler = new Handler();
private void doTheAutoRefresh()
{
handler.postDelayed(new Runnable() {
@Override
public void run()
{
// Write code for your refresh logic
doTheAutoRefresh();
}
}, 5000);
}
Answer:
Friends, I solved the problem and to better detail and share what I was able to do, I had to answer my own question and not just comment
I imported the library: using Android.OS;
I initialized Handler: Handler handler = new Handler();
I have a function that initializes the buttons 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, and already seen we are dealing with mobile devices with hardware that is mostly a little weak.