Similar function SwingUtilities.invokeLater in android?
Activity.runOnUiThread(Runnable action);
The above method is slightly different than invokeLater of java because it checks if you are already on ui thread then it will run your Runnable immediately.
There is another way to make sure your Runnable gets called later and not immediately even if you are on UI thread. To do that you write following code while you are on the main thread.. if you call this when on backend thread your runnable will be exected on backend thread..
Handler h = new Handler();
h.post(new Runnable() {
@Override
public void run() {
//your code..
}
);
Maybe you're looking for:
Activity.runOnUiThread(Runnable action)
I don't remember exactly what invokeLater()
does, but if you want to execute something delayed, you can use postDealayed(). That goes on the UI thread, so not fit for long running tasks, naturally.