Good day to all. It is necessary that every minute the title of my ActionBar in the Activity changed. There should be a time format mm:ss . Naturally, I will not engage in such a process in the main thread, and I created a separate one. But this team
getSupportActionBar().setTitle(new SimpleDateFormat("mm:ss").format(new Date(this.time))); requires me to run it in the main thread, and not in any other one, since Exception crashes. Rummaged on the Internet, where I was told that you can do this way
runOnUiThread(new Runnable() { @Override public void run() { getSupportActionBar().setTitle(new SimpleDateFormat("mm:ss").format(new Date(this.time))); } }); But, unfortunately, this option is not very good. By the fortieth minute, my application flew out for an unknown reason. Understood in the logs, and found that it took too many milliseconds to run the runOnUiThread , after which this command was simultaneously launched twice. I noticed that my title is changing unevenly. After all, it should be updated after 1000 ms, which means a second, but it is updated then 900 ms, then 1200 ms and so on. What is the reason I do not know. How to solve the problem so that the header changes exactly every 1000 ms?
I will ask you not to suggest me simply not to use the title, but to create some of my own, for example, TextView in Activity . Also, a bad option is getSupportActionBar().setCustomView(...) , as described here .