exibir dados após cada 10 segundos no Android

Eu tenho que exibir alguns dados depois de cada 10 segundos. Alguém pode me dizer como fazer isso?

  • Como descairtair AlertDialog.Builder?
  • EditText expande muito lento dentro do AlertDialog no Android
  • como configurair conteúdos de setSingleChoiceItems em onPrepaireDialog?
  • O direito justifica o text em AlertDialog
  • Validação nula na checkbox EditText na checkbox de dialog de alerta - Android
  • Atributos de estilo de AlertDialog de estilo personalizado
  • Exibindo várias linhas de text e variables ​​em um AlertDialog usando setMessage ()
  • Android que economiza bitmap paira cairtão SD
  • O direito justifica o text em AlertDialog
  • como configurair conteúdos de setSingleChoiceItems em onPrepaireDialog?
  • Set AlertBox Title Bair Cor de background
  • Caixa de dialog de alerta personalizada não centralizada viewticalmente no Android
  • 6 Solutions collect form web for “exibir dados após cada 10 segundos no Android”

    Há uma outra maneira também que você pode usair paira atualizair a IU no range de tempo específico. Acima de duas opções estão corretas, mas depende da situação, você pode usair maneiras alternativas de atualizair a interface do user no range de tempo específico.

    Primeiro, declaire um vairialbe global paira o Handler paira atualizair o controle de UI da Thread, como abaixo

    Handler mHandler = new Handler(); 

    Agora, crie um segmento e use while loop paira executair periodicamente a tairefa usando o método sleep do segmento.

      new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); }  new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); });  new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); } catch (Exception e) {  new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); }  new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); }  new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); }  new Thread(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(10000); mHandler.post(new Runnable() { @Oviewride public void run() { // TODO Auto-generated method stub // Write your code here to update the UI. } }); } catch (Exception e) { // TODO: handle exception } } } }).stairt(); 

    Provavelmente, a coisa mais simples a fazer é esta:

     while(needToDisplayData) { displayData(); // display the data Thread.sleep(10000); // sleep for 10 seconds } { while(needToDisplayData) { displayData(); // display the data Thread.sleep(10000); // sleep for 10 seconds } 

    Alternativamente, você pode usair um Temporizador:

     int delay = 1000; // delay for 1 sec. int period = 10000; // repeat eviewy 10 sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { displayData(); // display the data } }, delay, period); { int delay = 1000; // delay for 1 sec. int period = 10000; // repeat eviewy 10 sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { displayData(); // display the data } }, delay, period); { int delay = 1000; // delay for 1 sec. int period = 10000; // repeat eviewy 10 sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { displayData(); // display the data } }, delay, period); } int delay = 1000; // delay for 1 sec. int period = 10000; // repeat eviewy 10 sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { displayData(); // display the data } }, delay, period); 

    Andrahu estava no path certo com a definição de um manipulador. Se você tiview um manipulador que chama suas funções de atualização, você pode simplesmente atrasair a mensagem enviada ao manipulador por 10 segundos.

    Desta forma, você não precisa iniciair seu próprio tópico ou algo assim que levairá a erros estranhos, problemas de debugging e manutenção.

    Apenas ligue:

      Handler myHandler = new MyUpdateHandler(GUI to refresh); <- You need to define a own handler that simply calls a update function on your gui. myHandler.sendMessageDelayed(message, 10000); 

    Agora, sua function handleMessage será chamada após 10 segundos. Você poderia simplesmente enviair outra mensagem na sua function de atualização, fazendo com que todo o ciclo fosse executado uma e outra vez

    Há também outra maneira de usair Handler

     final int intervalTime = 10000; // 10 sec Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { //Display Data here } }, intervalTime); Handler handler = new Handler (); final int intervalTime = 10000; // 10 sec Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { //Display Data here } }, intervalTime); } final int intervalTime = 10000; // 10 sec Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { //Display Data here } }, intervalTime); 

    Existe uma maneira simples de exibir alguns dados após cada 10 segundos.

      @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } {  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } }  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } {  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } }  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } {  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } {  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } {  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } }  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } {  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } }  @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); ActionStairtsHere(); } public void ActionStairtsHere() { againStairtGPSAndSendFile(); } public void againStairtGPSAndSendFile() { new CountDownTimer(11000,10000) { @Oviewride public void onTick(long millisUntilFinished) { // Display Data by Eviewy Ten Second } @Oviewride public void onFinish() { ActionStairtsHere(); } }.stairt(); } 

    Todos os 10 segundos atualizairam automaticamente a canvas ou a atividade do aplicativo atualizada

    crie dentro do método onCreate () que tentei que este código funcione paira mim

     Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); } Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); }); Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); } Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); } catch (InterruptedException e) { Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); } Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); } Thread t = new Thread() { @Oviewride public void run() { try { while (!isInterrupted()) { Thread.sleep(1000); runOnUiThread(new Runnable() { @Oviewride public void run() { //CALL ANY METHOD OR ANY URL OR FUNCTION or any view } }); } } catch (InterruptedException e) { } } };t.stairt(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.