Em qual segmento o Runnable é executado?
Quero atualizar a interface do usuário a cada 100ms. Depois de pesquisar no StackOverflow, encontrei uma solução usandoRunnable
eHandler
como isso
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
//update UI here
handler.postDelayed(this, 100);
}
};
runnable.run();
Funciona! Mas eu tenho algumas perguntas:
Qual thread faz issoRunnable run on? MainThread or another thread? Here is the docs about <code>postDelay</code> <a href="/imgs/pIVPS.png" rel="noreferrer"><img src="/imgs/pIVPS.png" alt="enter image description here"></a>
Handler
está anexado MainThread, assim comoRunnable
rodando em MainThread?
Runnable
está sendo executado no MainThread, por que precisaHandler
? De acordo com o meu conhecimento,Handler
é usado para enviar mensagens entre dois threads