You have to move the portion of the background task that updates the UI onto the main thread. There is a simple piece of code for this:
runOnUiThread(new Runnable() { @Override public void run() { // Stuff that updates the UI } });
Documentation for Activity.runOnUiThread
.
Just nest this inside the method that is running in the background, and then copy paste the code that implements any updates in the middle of the block. Include only the smallest amount of code possible, otherwise you start to defeat the purpose of the background thread.
Related Posts:
- What is a mutex?
- What is a race condition?
- What’s the difference between deadlock and livelock?
- What is a “thread” (really)?
- What’s a Pthread?
- What is the difference between a process and a thread?
- What is the meaning of the term “thread-safe”?
- What are atomic operations for newbies?
- How to use multiprocessing queue in Python?
- Multiprocessing vs Threading Python
- Proper use of mutexes in Python
- How to pause / sleep thread or process in Android?
- What does threadsafe mean?
- java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
- How to avoid Not on FX application thread; currentThread = JavaFX Application Thread error?
- The application may be doing too much work on its main thread
- Java Wait for thread to finish
- How to “wait” a Thread in Android
- Semaphore vs. Monitors – what’s the difference?
- Why PTHREAD_COND_INITIALIZER may be used to initialize a condition variable only when it is declared?
- Service vs IntentService in the Android platform
- Difference between volatile and synchronized in Java
- Difference between user-level and kernel-supported threads?
- software threads vs hardware threads
- ‘App not Installed’ Error on Android
- Can’t start Eclipse – Java was started but returned exit code=13
- Mutex example / tutorial? [closed]
- Solving “adb server version doesn’t match this client” error [duplicate]
- How to display Toast in Android?
- ‘adb’ is not recognized as an internal or external command, operable program or batch file
- Flutter pageview : Find first and last page and swipe directions
- Enable VT-x in your BIOS security settings (refer to documentation for your computer)
- Unfortunately MyApp has stopped. How can I solve this?
- Default Activity not found in Android Studio
- C++ terminate called without an active exception
- how to overcome Android Studio cannot resolve symbol for android classes
- ADB Android Device Unauthorized
- Why fragments, and when to use fragments instead of activities?
- SQLiteDatabase.query method
- Android ADB device offline, can’t issue commands
- Android SDK location
- Android Studio Run/Debug configuration error: Module not specified
- IllegalArgumentException: Unable to locate adb in Android Studio v2.3
- How to set the text color of TextView in code?
- What is the “AdMob Offline Notifications” notification channel?
- Why am I seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors after upgrading to Cordova Android 8?
- A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
- Timeout on a function call
- Getting weather info feeds from accuweather
- adb command not found
- Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?
- align text center with android
- Extending from two classes
- Android basics: running code in the UI thread
- local variables referenced from an inner class must be final or effectively final
- Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’
- Horizontal ListView in Android?
- Eclipse error, “The selection cannot be launched, and there are no recent launches”
- RecyclerView onClick
- How to customize a Spinner in Android
- How to create JSON Object using String?
- Dialog throwing “Unable to add window — token null is not for an application” with getApplication() as context
- Why doesn’t RecyclerView have onItemClickListener()?
- Android Studio: “Execution failed for task ‘:app:mergeDebugResources’” if project is created on drive C:
- Mipmaps vs. drawable folders
- How to pass an object from one activity to another on Android
- What is the meaning of android.intent.action.MAIN?
- Disable back button in android
- How to clear gradle cache?
- Android For loop
- Converting pixels to dp
- How do I download the Android SDK without downloading Android Studio?
- Aspect Ratio with 800×480
- android edittext onchange listener
- E/AndroidRuntime﹕ FATAL EXCEPTION: main
- Difference between getContext() , getApplicationContext() , getBaseContext() and “this”
- adb socket not working and daemon
- Installation error: INSTALL_FAILED_OLDER_SDK
- Unable to load script from assets index.android.bundle on windows
- Default FirebaseApp is not initialized
- Detecting a long press with Android
- How can I create simple accordion with Angular 2?
- Detect a finger swipe through JavaScript on the iPhone and Android
- Reverse engineering from an APK file to a project
- How can I wait for 10 second without locking application UI in android [duplicate]
- How to disable Instant Run for Android Studio 3.0
- I can’t find adb_usb.ini file in .android folder?
- Android; Check if file exists without creating a new one
- How to open adb and use it to send commands
- Can I get Unix’s pthread.h to compile in Windows?
- Unable to add window — token null is not valid; is your activity running?
- How fix Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
- Android: how to create Switch case from this?
- How to remove title bar from the android activity?
- Call requires permissions that may be rejected by user
- WordPress Respond.io Web Chat Widget not working properly on Android
- How do I make my blog iPad / iPhone / Android friendly?
- Mobile User Registration
- Disable save as image on smartphones using all browsers ( chrome, firefox, ie, cm, opera )
- Add wordpress user database on android app