How to Start a Background Thread in Android
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about frozen UIs, background work and running code off the main thread in Android.
Recommended by 2 people across 3 different months, 2018 to 2021.
What it is
A 16-minute Android tutorial from the Coding in Flow channel on moving long-running work off the main thread. It covers creating worker threads via Thread and Runnable, then posting results back to the UI thread using Handler, Looper, View.post and runOnUiThread.
What people said
Strong rec sandhya sasane · 2019-02 · Stack Overflow · on “UI Freezing while doing heavy processing in background Android”
The Simplest, Best and visual example with demonstration how exactly it should be, if you do not want to freeze the UI. Everyone who are facing this problem or anyone who are unaware of how to code for the android projects, should see and follow this style : Video Demonstration of Avoiding UI freezing [this video]
Recommends sandhya sasane · 2018-09 · Stack Overflow · on “MainActivty isn't starting on Nougat and Oreo”
No way... I am not writing it as answer ; which i will delete once he will read it. But if followed line by line and after doing same changes it will get resolved too Stop coding thousands of lines in your mainsctivity It is not the place where all code and logic and operations goes...!! What is mainActivity for then,,,?? As per my knowledge For only 100 lines of code What that 100 lines of code should do? Check android version , if above Marshmallow ask permissions on below do nothing. And start the services on main thread or start the another threads for operations and tasks..!! Solution : Make a new project by taking a sample code of navigation project which is given ready made in android
Recommends sandhya sasane · 2018-09 · Stack Overflow · on “Thread freezes the UI when using a while loop inside Run() method of Runnable object”
Will you please listen and see how exactly run a thread, off the main thread so that UI never blocks or never skips any frames [this video]
Recommends Mena · 2020-12 · Stack Overflow · on “Can adding anonymous runnables in the queue of a Handler thread cause a memory leak?”
In Java, non-static inner and anonymous classes hold an implicit reference to their outer class. Static inner classes, on the other hand, do not. Avoid using non-static inner classes in an activity if instances of the inner class could outlive the activity’s lifecycle. Instead, prefer static inner classes and hold a weak reference to the activity inside. Source 1 [LINK] Source 2 [LINK] As for doing the same in the ViewModel instead of an Activity, if a memory leak occurs it will have a lesser magnitude in case the ViewModel didn't hold a reference to memory-intensive objects that should be garbage collected. But still, a memory leak threat would be still possible. This Link [LINK] is also ve
Cites Aaditya Burujwale · 2021-06 · Stack Overflow · on “How to run specific methods infinite time in background per 5 seconds in android?”
I got the solution of my answer by watching this video [this video] . I have to use Thread Or Runnable Interface to do that in background.