Explained - Android UI thread/main thread

  Рет қаралды 68,647

Codetutor

Codetutor

Күн бұрын

In Android writing the code without blocking the UI thread is once of the important concept. This video talks about how the app are treated as individual processes in Android and the UI task is always performed on the UI thread also referred to main thread. The video then does on to demonstrate what happens when your code runs on UI thread and how the solve that problem.
Follow me on Twitter: / anilvdeshpande

Пікірлер: 64
@fritzauguste6669
@fritzauguste6669 2 жыл бұрын
Wow i am so glad i landed on this explanation first, very clear.
@hafizdwp
@hafizdwp 7 жыл бұрын
BEST EXPLANATION! thank you very much
@prashantkamble898
@prashantkamble898 7 жыл бұрын
Very best explanation. Very easy to understand. Thank you
@baghi3hi219
@baghi3hi219 3 жыл бұрын
This is theqawedwaedf original comment.
@kavie8257
@kavie8257 7 жыл бұрын
Great Explanation.Still now I didn't find this kind of explanation anywhere.Thanks a lot...
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 7 жыл бұрын
+Kavitha Nagarajan Thanks for the feedback.. Glad that you found the content useful. Feel free to visit playlist section (bit.ly/2wtwbQ2) to see what other concepts on Android have been covered so far. Help spread the word about the channel. Hope you have subscribed...
@be.happyfaces
@be.happyfaces 7 жыл бұрын
Nice explanation. Thank you sir
@antoneltonij8362
@antoneltonij8362 3 жыл бұрын
Thank! Nice illustration, nice explanation
@Quancept
@Quancept 5 жыл бұрын
That was a very good explanation. Thanks!
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 5 жыл бұрын
Hey thanks.. Glad that you liked the content. Feel free to explore other videos, visit playlist section of channel to see curated content. Hope you have subscribed.
@karthikvs2152
@karthikvs2152 3 жыл бұрын
accurate and easy to understand . thank you so much sir
@eduardocardozo6737
@eduardocardozo6737 3 жыл бұрын
Simple and clear.
@karthikkrishnaswamy415
@karthikkrishnaswamy415 7 жыл бұрын
Very well explained..
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 7 жыл бұрын
Thanks...Stay tuned as I shall be publishing videos on Looper and Handler to deal with slightly complicated scenarios...
@vinodkamble3818
@vinodkamble3818 7 жыл бұрын
Nice explanation
@priyadharshinik1088
@priyadharshinik1088 5 жыл бұрын
Awesome tutorials.. Keep doing the same sir... 🤝🏻
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 5 жыл бұрын
Thanks.. Help read the word about the channel. If you like something, please share the video with your friends and peers who might find it useful too.
@aviksutar
@aviksutar 6 жыл бұрын
Make some videos on MVP, MVVM, MVA, Callback. Because most of the interviewers focuses on these topic now a days.I am writing these as your explanations are very nice.Thank you for helping.
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 6 жыл бұрын
Thanks for commenting.. One of the biggest debate among Android developers is - Which of the following MVC, MVP, MVVM, MVA are suited for Android architectures? The recent Android Architecture components that Android officially proposes make it even more clear that Android is not suited for MVC. Even MVP has it's problems with how Android components are designed. MVVM seems to be the most properly suited architecture for Android. I definitely have future plans to create content on these, but these things will take some time - as I am busy with other fundamental topics that I intend to cover in Android. If you have any interesting article/blog/github posts on these topic please let me know. It will help me create a good references when I decide to create content. The more exhaustive literature survey is, better the content will be and I don't mind help coming from any where :-)
@vikashgauravvkg
@vikashgauravvkg 6 жыл бұрын
Awesome explanation
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 6 жыл бұрын
hey thanks.. see you around.
@rajivkumargupta8467
@rajivkumargupta8467 6 жыл бұрын
Useful knowledge... thanks sir
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 6 жыл бұрын
You are welcome. Feel free to explore other content on channel - visit play list section of the channel. Hope you have subscribed.
@revansiddappakalshetty4827
@revansiddappakalshetty4827 7 жыл бұрын
very nicely explained
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 7 жыл бұрын
Thanks... stay tuned
@medgabsent9615
@medgabsent9615 7 жыл бұрын
subscribe , because explaining using demos much easy to understand good work !!.
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 7 жыл бұрын
+MedG Absent thanks for subscribing.... Stay tuned for more interesting content..
@TRK21
@TRK21 7 жыл бұрын
i am using checkbox to on and off flashlight .........after starting service(flash light is on state) wen we close and open application the checkbox is showing unchecked state but still flash is in on state.....hw to solve this
@forpayonerr1149
@forpayonerr1149 5 жыл бұрын
great explanation
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 5 жыл бұрын
Feel free to explore other content on playlist section of the channel. Hope you have subscribed.
@freshfast6197
@freshfast6197 5 жыл бұрын
2:30 demo 4:04 onClick(View v) using Switch statement and Boolean flag 4:24 putting loop on separate thread : new Thread(new Runnable { public void run () { while (mStopLoop) { .. } } }).start(); 5:15 now different Thread id showing in logcat 5:37 separate thread use case advice
@rajivraghu9857
@rajivraghu9857 7 жыл бұрын
Thanks :)
@zahidali-pv8vp
@zahidali-pv8vp 8 жыл бұрын
Nice tutorial thanks sir. sir please also deliver tutorial on process
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 7 жыл бұрын
Thanks... stay tuned.. one of these days you may get the topic that you suggested...cheers.. happy coding..
@StereoWorld
@StereoWorld 3 жыл бұрын
Etv music in the intro
@prashantkamble898
@prashantkamble898 7 жыл бұрын
Please explain me what is role of runOnUIThread method in android?
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 7 жыл бұрын
In Android any UI related work needs to run on main/UI thread. But some times to reduce the burden on main thread, you may start a thread. After that thread completes or during it's execution, you may want to update the UI with some information from that thread. That is not possible. Because the thread that you have created is not UI thread. That is where runOnUIThread comes in to picture. you can invoke this method inside you thread. This is execute the part of code, that you want to run on main/UI thread , on main/UI thread. So it's a handy mechanism provided by Android to push work from non-UI thread to UI thread.
@fulbiofernandopretelllozan4754
@fulbiofernandopretelllozan4754 6 жыл бұрын
Maestro resuelveme una duda porfavor, cuando hablas de diferentes procesos (process /App) te refieres a diferentes apps? O estos procesos están en la misma aplicación???
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 6 жыл бұрын
In Android each and every app has a process of it's own. So basically each app gets a dedicated process.Since each app runs in it's own process they can't interfere with one another (unless you want interprocess communication) . This makes OS more complex but also robust. If all apps were hosted in one process, then for example your music player app and caller app would be in same process. If Music app crashes then it will take the caller app also down with it. If these two were separate processes, then only music app will get crashed and caller app will continue to work just fine. I intentionally wrote this in English because I don't trust how Google Translate is going to translate what I may intend to say. I want to be sure that I mean what I write. I hope I have not confused you more with this.
@fulbiofernandopretelllozan4754
@fulbiofernandopretelllozan4754 6 жыл бұрын
understood teacher, better I use the translator for your convenience, thank you for sharing your knowledge ... regards
@sana_r_1212
@sana_r_1212 5 жыл бұрын
Hi sir, I'm facing some ANR problem while performing setadapter for Listview . My activity contains 3listview and many other (textview ..) and in that 1 Listview is always visible and consist 7 items and 2nd list view is visible only some cases and 3rd list view consist of huge items like I'm getting items of 3rd Listview from server by using asynctask and after getting items I'm not displaying it immediately.. initially my 3rd Listview is hidden when user click on title layout I'm performing setadapter for my 3rd Listview and making it visible . But the problem is here it's. Taking more time and showing ANR. I tried putting setadapter I'm asynctask , and showing progress dialog while setting adapter so that users can not perform other ui operation . But after setting adapter after progress bar dismiss also it's taking 20-30 seconds for making Listview visible .. Please help me..
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 5 жыл бұрын
As explained in the video ANR happens when you are doing something on UI thread which is blocking it for more than five seconds. It would very difficult to guess the root cause of the problem based on just the description you have given. But I feel there is something wrong in the way you are initializing the View in 3rd ListView. Consider caching the web service response so that View can be set quickly. There is an option of Lazy Loading as well. Have you debugged the application - at which juncture the UI thread gets blocked? Use CPU and Memory profiler tools (part of Android Studio) to understand where resources are being used excessively.
@noreply2030
@noreply2030 4 жыл бұрын
THANKS YOU
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 4 жыл бұрын
Thanks for the kind words. Feel free to explore other content on channel. Visit the play list section. Hope you have subscribed.
@sammyplexus96
@sammyplexus96 6 жыл бұрын
Nice tutorial. Thanks. I am a little confused as to why the stop button didn't stop the logging until only when it was put in a new thread. I thought changing the Boolean value should have nothing to do with the thread. can you please explain?
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 6 жыл бұрын
Watch the complete series...
@sammyplexus96
@sammyplexus96 6 жыл бұрын
Codetutor Thanks!
@sammyplexus96
@sammyplexus96 6 жыл бұрын
Codetutor Thanks!
@vishnujm242
@vishnujm242 4 жыл бұрын
Loop doesn't stop immediately after setting mStopLoop = false. It is stopping after long time due to "read: unexpected EOF!" Please explain why
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 4 жыл бұрын
Since there is not real delay in the loop inside run, the logs you are seeing is not in sync with the exact moment when mStopLoop becomes false. Just add a 1 second Thread sleep and see what happens. Not as far as read: unexpected EOF! is concerned, it is not related to the code we have written. I think since lots of Logs are being written, it is affecting Android Studio. You need to increase Log buffer size of Android Studio. At least this is what I got to know when I went through some Stackoverflow posts.
@jaitpurhighschool7078
@jaitpurhighschool7078 4 жыл бұрын
Hey your video is good but when I am am making a sample then that time thread is automatic stopping after some interval of time, Please let me know why Its happening.
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 4 жыл бұрын
I suggest you check out the code from Github link I have given in description section of the video. You can compare the code you have written and I have written - or even fork my code. It will be easy to track the differences.
@arjunkhanna1803
@arjunkhanna1803 3 жыл бұрын
explaination is very good but could you please improve the voice quality?
@OmPrakash-hs3tw
@OmPrakash-hs3tw 6 жыл бұрын
Please provide videos of parcelable in android.Because Parcelable is very much required when you use bulk of data to pass from one activity .Thanks in advance.
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 6 жыл бұрын
Hi Om, Parcelable has been covered on Codetutor previously. Please visit: kzfaq.info/sun/PLfuE3hOAeWhbtEnCB0-vuF2hSmwGAAeea
@citylifecantonese
@citylifecantonese 4 жыл бұрын
but this does not stop the loop thread, it may be memory leakage. and consumer a lot of bettery
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 4 жыл бұрын
Yes... for example the UI thread itself is a Looper which continuously runs to execute anything related to UI.
@MuhammadAli_hub
@MuhammadAli_hub 3 жыл бұрын
Short and at the same time Comprehensive....
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 3 жыл бұрын
Glad that you found it useful. Feel free to explore other content on channel. Visit playlist section. Hope you have subscribed.
@gateblog892
@gateblog892 5 жыл бұрын
1) Sir, can't i check this while loop execution using my mobile phone instead of emulator 2)And OnCreate() method itself is the "main Thread/UI thread right sir??
@Codetutor-DemystifyCoding
@Codetutor-DemystifyCoding 5 жыл бұрын
Ans 1: You can, enable the debug mode on your Android device and run the app on device (find out how to do this :-) ) Ans 2: Yes, your understanding is right.
@gateblog892
@gateblog892 5 жыл бұрын
@@Codetutor-DemystifyCoding Woah!! Thanks a lot sir.
@ingenieurinformatik2037
@ingenieurinformatik2037 5 жыл бұрын
Very bad accent.
@ingenieurinformatik2037
@ingenieurinformatik2037 5 жыл бұрын
If you explain good and we don’t listen any word, that serve no purpose
Explained - Android Looper and handler
6:25
Codetutor
Рет қаралды 61 М.
Runnables Threads and Handlers in Android
10:07
Mafia Codes
Рет қаралды 36 М.
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 12 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 5 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 56 МЛН
FANG Interview Question | Process vs Thread
3:51
ByteByteGo
Рет қаралды 299 М.
Stop, Intel’s Already Dead!
13:47
Linus Tech Tips
Рет қаралды 266 М.
What Is Kotlin Multiplatform And How Does It Work? - KMP for Beginners
10:17
7 FUN guitar LOOPING songs | and HOW TO DO IT!
11:58
Paul Davids
Рет қаралды 2,2 МЛН
Explained - Creating custom Looper & Handler
7:37
Codetutor
Рет қаралды 13 М.
How I Would Learn To Code (If I Could Start Over)
13:43
Namanh Kapur
Рет қаралды 7 МЛН
Fundamentals of Compose Layouts and Modifiers - MAD Skills
11:56
Android Developers
Рет қаралды 89 М.
Хакер взломал компьютер с USB кабеля. Кевин Митник.
0:58
Последний Оплот Безопасности
Рет қаралды 2,3 МЛН
ноутбуки от 7.900 в тг laptopshoptop
0:14
Ноутбуковая лавка
Рет қаралды 3,6 МЛН
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 503 М.
Как удвоить напряжение? #электроника #умножитель
1:00
Hi Dev! – Электроника
Рет қаралды 1,1 МЛН
Nokia 3310 top
0:20
YT 𝒯𝒾𝓂𝓉𝒾𝓀
Рет қаралды 4,4 МЛН
Сколько реально стоит ПК Величайшего?
0:37