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
- how to set the background color of the status bar during the launching phase [duplicate]
- How to show a loading gif while an APi is being called in xamarin android?
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- Dial pad to get phone number (with Android button images)
- Emulator: ERROR: x86 emulation currently requires hardware acceleration
- Emulator: ERROR: x86 emulation currently requires hardware acceleration
- ‘App not Installed’ Error on Android
- pthread_join() and pthread_exit()
- ‘App not Installed’ Error on Android
- Draw a transparent circle onto a filled android canvas
- Python time.sleep() vs event.wait()
- How to use navigateUp to close the application
- “unable to locate adb” using Android Studio [duplicate]
- “unable to locate adb” using Android Studio [duplicate]
- Can’t start Eclipse – Java was started but returned exit code=13
- Can’t start Eclipse – Java was started but returned exit code=13
- What exactly is “com.google.android.packageinstaller”
- Differences between arm64 and aarch64
- Converting double to string
- Android WebView err_unknown_url_scheme
- google console error `OR-IEH-01`
- Undefined reference to pthread_create in Linux
- Install an apk file from command prompt?
- Mutex example / tutorial? [closed]
- How to decompile an APK or DEX file on Android platform? [closed]
- Install an apk file from command prompt?
- Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
- Error parsing data org.json.JSONException: Value
- What does “|=” mean? (pipe equal operator)
- My users get “net::err_name_not_resolved”
- Error – Android resource linking failed (AAPT2 27.0.3 Daemon #0)
- Solving “adb server version doesn’t match this client” error [duplicate]
- Error: No toolchains found in the NDK toolchains folder for ABI with prefix: llvm
- Unity remote 5 not working
- Error – Android resource linking failed (AAPT2 27.0.3 Daemon #0)
- Solving “adb server version doesn’t match this client” error [duplicate]
- Error: No toolchains found in the NDK toolchains folder for ABI with prefix: llvm
- How to display Toast in Android?
- What is Android’s file system?
- How to use adb command to push a file on device without sd card
- Can’t create handler inside thread that has not called Looper.prepare()
- What is a StringIndexOutOfBoundsException? How can I fix it?
- recyclerview No adapter attached; skipping layout
- Exception : AAPT2 error: check logs for details
- This adb server’s $ADB_VENDOR_KEYS is not set
- Can’t create handler inside thread that has not called Looper.prepare()
- This adb server’s $ADB_VENDOR_KEYS is not set
- ‘adb’ is not recognized as an internal or external command, operable program or batch file
- How do popBackStack() and replace() operations differ?
- E: unable to locate package pip
- recyclerview No adapter attached; skipping layout
- Exception : AAPT2 error: check logs for details
- Flutter pageview : Find first and last page and swipe directions
- What are the possible reasons for NFC Service to become dead after some time?
- How can I find and run the keytool
- Android ADB devices unauthorized
- adb is not recognized as internal or external command, operable program or batch file
- Enable VT-x in your BIOS security settings (refer to documentation for your computer)
- NetworkType.UNMETERED vs NetworkType.METERED – PeriodicWork
- @ converted to %40 in HTTPPost request
- Getting net::ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android
- Simple Android RecyclerView example
- Find all Bluetooth devices (headsets, phones etc) nearby, without forcing the devices in discoverable mode
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- “Default Activity Not Found” on Android Studio upgrade
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- Unfortunately MyApp has stopped. How can I solve this?
- Still getting warning : Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’
- What is ‘Context’ on Android?
- How to install APK from PC?
- What exactly is std::atomic?
- How to convert any Object to String?
- android image button
- Default Activity not found in Android Studio
- What causes signal ‘SIGILL’?
- Unfortunately MyApp has stopped. How can I solve this?