How can I invoke method in endless loop that way it would be invoked every 200ms? What I mean is: sendMessage()
-> wait(200ms) -> sendMessage
-> wait(200ms) and so on, endlessly unless the user decides not to by pushing button. Here is sendMessage
method as an example:
private void sendMessage(String message) {
if (mCommandService.getState() != CommandService.STATE_CONNECTED) {
Toast.makeText(this, R.string.title_not_connected, Toast.LENGTH_SHORT).show();
return;
}
if (message.length() > 0) {
byte[] send = message.getBytes();
mCommandService.write(send);
mOutStringBuffer.setLength(0);
mOutEditText.setText(mOutStringBuffer);
}
}
I can not use Thread.sleep()
as it would freeze the UI. Idea with handler.postDelayed()
is not viable here aswell I guess. Or maybe it is? How can I achieve that? I can not freeze any of the activities anyhow...