Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

Run Callback On Main Thread

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        //execute code on main thread
    }
});

As long as you have a Context, you can do something like this:

Handler mainHandler = new Handler(context.getMainLooper());

And to run code on UI thread:

mainHandler.post(new Runnable() {

    @Override
    public void run() {
        // run code
    }
});

As suggested by kaka:

You could also use the static Looper.getMainLooper() which

Returns the application's main looper, which lives in the main thread of the application.

Tags:

Android

Cocos2D X

Related

How to compile an example SDL program written in C? Form Submit button only works after reload How to add an extra row to a pandas dataframe Rationale for 509 minimum character limit Compilation fails with "relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object" How to view the list of compile errors in IntelliJ? How to center ordered list number in HTML Issue making Bootstrap3 icon spin Adding superscript <sup> tags around all trademark and registered trademark symbols MVVM RelayCommand CanExecute Replace None value in list? MVC5 Claims version of the Authorize attribute

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy