Github link to source code: github.com/AnilDeshpande/UIThreadDemo/tree/handler-code
@thomasamathew40585 жыл бұрын
Keep up the good work . One of the best classes I've seen on the topic
@sanjaymallur86127 жыл бұрын
Very good explanation. Keep it up. Voted Up.
@gilong13112 жыл бұрын
Finally a good explanation of handlers and loopers, well done!
@nexgen.graphics5 жыл бұрын
Thanks for breaking this complex thing in simple words. Really appreciate your efforts in bringing these concepts to the beginners.
@Codetutor-DemystifyCoding5 жыл бұрын
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.
@rishavmasih9450 Жыл бұрын
This to the point and concise. Love your videos.
@drishandroid71176 жыл бұрын
This is the best explanation found so far. Thanks for your efforts.
@Codetutor-DemystifyCoding6 жыл бұрын
Thanks.. Glad that you liked the content. Visit playlist section to check out other content on the channel. Hope you have subscribed.
@sauri20057 жыл бұрын
Great tutorial. Great concept overview . Would love to see more tutorials with intent service and async task with practical examples of scenarios suited to each. Thank you and please upload more videos Subscribed
@Codetutor-DemystifyCoding7 жыл бұрын
Thanks... I have a detailed series on Services in general.. you can have a look at this kzfaq.info/sun/PLfuE3hOAeWhbm-_mNEbVdQuaac7Rd4TgZ Stay tuned.. The topics suggested by you are in my TODO list for quite some time... Pretty soon you will be notified... Thanks for subscribing....
@hemaladani45107 жыл бұрын
Nicely done. With example and visualization.
@thiru0murugan4 жыл бұрын
Excellent explanation about looper, handler and how it works.
@Codetutor-DemystifyCoding4 жыл бұрын
Thanks for the kind words. Feel free to explore other content on Codetutor- visit playlist section. Hope you have subscribed.
@kritikamadhwani28363 жыл бұрын
The Simplest and the Best explanation yet!
@Codetutor-DemystifyCoding3 жыл бұрын
Glad that you found it useful. Feel free to explore other content on channel. Hope you have subscribed.
@antoneltonij83623 жыл бұрын
Excellent explanation! Thanks!
@suryajeetsingh7 жыл бұрын
Nice explanation !!
@videosyoutube7187 жыл бұрын
Amazing job, thanks you so much!!!
@ankit_khachane5 жыл бұрын
Thanks Codetutor this videos explained about android main threads that i didn't know until today.
@Codetutor-DemystifyCoding5 жыл бұрын
Thanks.. Feel free to explore other content on channel. Visit the playlist section of the channel. Hope you have subscribed.
@ankit_khachane5 жыл бұрын
@@Codetutor-DemystifyCoding Yes ! i have subscribed and learning rest of the android core topic
@CuiqkOfficial6 жыл бұрын
@Codetutor I spent so much time on these topics to understand, but now I came to a conclusion that I should have watched your videos before. It saved a lot of time. One thing about code, you don't have to instantiate your Handler using getMainLooper() method. You could have just used Handler() with no arguments as long as you are instantiating it in the UI thread. getMainLooper() is only needed if you instantiate Handler from a non UI thread.
@Codetutor-DemystifyCoding6 жыл бұрын
Yeah.. I know.. As I have commented before, I just wanted to make absolutely sure that audience understands that we are dealing with main thread... That's all. Thanks for commenting.
@abhijittaware4360 Жыл бұрын
very good explaination. you saved the day for me
@dadi97957 жыл бұрын
Thank you, now I understand Android Thread better!
@megood15827 жыл бұрын
thanks for the explanation, i get a better understanding of this topic
@MithunCN4 жыл бұрын
very clear explanation. thank you. i am making a notes of the concepts which u teach, if see the notes even after few months i can get the concept clearly.
@arvindpatil44513 жыл бұрын
Excellent way of explanation sir... I am learning so many things from Your videos . Thank you sir
@Codetutor-DemystifyCoding3 жыл бұрын
Thanks for the kind words, Glad that you found the content useful.
@MarioMoreno19925 жыл бұрын
Simple and great video, thanks!
@Codetutor-DemystifyCoding5 жыл бұрын
Thanks.. Glad that you are liking the content on the channel. Feel free to explore other content on channel - visit the playlist section of the channel to have a curated content. Hope you have subscribed.
@rohithegde92395 жыл бұрын
Excellent explanation sir...Keep making more videos. Thank you.
@Codetutor-DemystifyCoding5 жыл бұрын
You are welcome. Help spread the word about the channel. Share it among your friends and peers. Hope you have subscribed.
@basavarajashok5 жыл бұрын
Thank you . Your tutorials are too good in understand
@Codetutor-DemystifyCoding5 жыл бұрын
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.
@nikhilagrawal9217 Жыл бұрын
Thank you so much for this video.
@LearnInspireGrow99034 жыл бұрын
Nice explanation and demo.
@Codetutor-DemystifyCoding4 жыл бұрын
Thanks for the kind words. Feel free to explore other content on channel - visit the playlist section of the channel. Hope you have subscribed.
@currenthacker38773 жыл бұрын
Explained very well
@vijaynath19866 жыл бұрын
Thank you sir. Awesome way of teaching.
@Codetutor-DemystifyCoding6 жыл бұрын
Thanks.. Glad that you liked the content.. Please visit the playlist section of the channel to see other content.. Hope you have subscribed...
@hafizdwp7 жыл бұрын
very good explanation. thank you
@sahilkhatri45612 жыл бұрын
great explanation!! pls keep on making videos on android and pls try to start making videos on IOS as well. thank you!!
@jackchang9677 жыл бұрын
thank you!! learn a lot from this video
@Codetutor-DemystifyCoding7 жыл бұрын
Glad that you liked it. Please visit kzfaq.infoplaylists to have a look at other interesting content.
@kshitijgarg26092 жыл бұрын
Best explanation, so thanks of you
@Codetutor-DemystifyCoding2 жыл бұрын
You are welcome. Feel free to explore other videos on Codetutor. Visit the playlist section of the channel. Hope you have subscribed.
@MukhtaarAAziz-ho5hc7 жыл бұрын
many many thanks bro :)
@chandanlal7865 жыл бұрын
Nice video keep posting
@Codetutor-DemystifyCoding5 жыл бұрын
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.
@abhib4390 Жыл бұрын
Good explanation thank you
@duyhoang53346 жыл бұрын
thanks , that's awesome explanation
@Codetutor-DemystifyCoding6 жыл бұрын
Thanks.. glad that you found the content useful. Feel free to check other content from the Channel playlist section. Hope you have subscribed.
@basavarajashok5 жыл бұрын
nice explanation . Thank you
@Codetutor-DemystifyCoding5 жыл бұрын
Thanks.. Glad that you are liking the content on the channel. Feel free to explore other content on channel - visit the playlist section of the channel to have a curated content. Hope you have subscribed.
@DonkeyFrog5 жыл бұрын
Excellent video
@Codetutor-DemystifyCoding5 жыл бұрын
Thanks... Feel free to explore other Android related content on Codetutor. Visit the playlist section of the channel to have look at curated list. Hope you have subscribed.
@kamesh0767 жыл бұрын
Codetutor I liked the explanation, can you please explain me when the HandlerThread is used ? What's the difference between Handler and Handlerhread ?
@shubham53995 жыл бұрын
Amazing explanation
@Codetutor-DemystifyCoding5 жыл бұрын
Thanks.. Feel free to explore other content on channel. Visit the playlist section of the channel. Hope you have subscribed.
@boominathanarumugam55896 жыл бұрын
I think He is a Good Shepherd for Basic Android Programmers
@brucebane74013 жыл бұрын
in the first example how is the new thread able to verify the value of mstoploop variable wasnt it created in the original/main thread
@next49786 жыл бұрын
Seems some very useful core concept for advanced development
@Codetutor-DemystifyCoding6 жыл бұрын
Hey thanks.. Feel free to explore other content on channel - visit playlist section of the channel. Hope you have subscribed.
@MohamedISoliman6 жыл бұрын
keep it up, good explanation
@Codetutor-DemystifyCoding6 жыл бұрын
Thanks... Glad that you liked the content...Help spread the word about channel..
@mateenchaudhry73636 жыл бұрын
Sir you are awesome God bless you :)
@Codetutor-DemystifyCoding6 жыл бұрын
+Mateen Chaudhry hahaha...thank you.. hope you have subscribed.. visit playlist section of video to see which other topics are discussed in channel so far
@videossoma7 жыл бұрын
greatly explained. can u please make video on image processing in Android?
@aalap037 жыл бұрын
hey very nice tutorial, one question though... another way to update the text inside thread is directly call runonuithren method and inside u can set text... instead of creating handler instance and inside creating runnable instance...
@Codetutor-DemystifyCoding7 жыл бұрын
+Aalap Patel you are absolutely right.. and runOnUiThread actually uses the same concept , it's just that it abstracts all that painful gory details of handler and looper from developers.
@hemaladani45107 жыл бұрын
What is the material that you refer to if needed in terms of Android?
@Codetutor-DemystifyCoding7 жыл бұрын
It varies... My main goto resource is official documentation then blogs, stack-overflow in case I am looking for something specific. I also watch videos (KZfaq and other online tutorial series). Little bit of smart Google Search also helps. Typically I prefer to go through content from multiple places on same subject/concept to see whether everyone is saying same thing about a particular concept and then verify it for myself via coding actually lot of coding to create POCs.
@rohithegde92395 жыл бұрын
Hi sir, I would like to correct you on this. The handler actually automatically has the reference to the message queue of the thread that is creating it. So here you are creating the handler on the UI thread, so it has the reference of UI thread's message queue. Hence you do not need to pass the main looper to it. Handler handler = new Handler(getApplicationContext().getMainLooper()) can be just written as Handler handler = new Handler();
@Codetutor-DemystifyCoding5 жыл бұрын
You and me are on the same page here. As I have commented before, I have used new Handler(getApplicationContext().getMainLooper())because it wanted to make it more explicit about the reference to the UI thread looper queue. I have clarified about it before as well in comment section.
@mohammedviso22697 жыл бұрын
Thanks a lot
@prabhusingh10156 жыл бұрын
In ui thread if want to perform some action on button click that will also add in message queue?
@Codetutor-DemystifyCoding6 жыл бұрын
Yes...
@prabhusingh10156 жыл бұрын
@@Codetutor-DemystifyCoding thnx for rply sir and pls make some video on mvvvm.
@kavie82576 жыл бұрын
Hi, Will UI Thread also placed in Message Queue?
@Codetutor-DemystifyCoding6 жыл бұрын
No...
@axelc91225 жыл бұрын
Thanks!!
@Codetutor-DemystifyCoding5 жыл бұрын
Thanks.. Glad that you are liking the content on the channel. Feel free to explore other content on channel - visit the playlist section of the channel to have a curated content. Hope you have subscribed.
@gauravthakkar8023 жыл бұрын
Coming in around 2021, if you would like to create your own handler and associate it with the main/ui thread looper, you can go with the approach But I have often seen developers using the Activity method called as runOnUiThread(Runnable runnable) Even this can manipulate ui thread from other threads, usually you need to change ui , so I can conveniently say,"Update UI from any other thread other than main thread"
@karthikhb22797 жыл бұрын
super :)
@elvinahuang21715 жыл бұрын
Awesome
@MrPatelUtsav6 жыл бұрын
Too Good.
@Codetutor-DemystifyCoding6 жыл бұрын
Hey.. Thanks.. Feel free to visit playlist section of the channel to see other content available on Codetutor. Hope you have subscribed.
@anjalinitish70596 жыл бұрын
Nice!
@Codetutor-DemystifyCoding6 жыл бұрын
Thanks.. Check out the other content on channel - visit the playlist section. Hope you have subscribed.
@sushilkumargouda81015 жыл бұрын
Sir I am not getting any exception
@karthikkrishnaswamy4157 жыл бұрын
I some how got the concept of Activity.runOnUiThread(Runnable) and View.post(Runnable).But didn't understand Handler concept and why should i use it.Your video cleared my doubts on an handler.Thank you. But still i got few doubts,which method is preferred to update the UI thread? is it Activity.runOnUiThread(Runnable) or View.post(Runnable) or Handler ?
@Codetutor-DemystifyCoding7 жыл бұрын
Hi Karthik... "Handler" is a very generic concept.. it basically provides you a mechanism to access the looper Message Queue. In this particular case we are talking about UI thread Message Queue. The "runOnOnUIThread" and "view.post" will automatically help you to access the Handler object associated with the UI thread Message Queue. Both methods pretty much do one and the same.. You can use either of them... However in some scenarios you may want to interact with some other thread (which is a non UI thread)... Then this (non-UI) thread needs to be a looper (with it's own message) and to post messages to this looper thread you need to have your own instance of Handler. In this case you can't use Activity.runOnUiThread(Runnable) or View.post(Runnable) as they are only meant for updating the Message Queue of UI thread/looper. This is definitely more tricky and requires more intricate understanding of Threads.. Looper and Handler. I am definitely going to make a video on this... I hope right now,this explanation helps...
@karthikkrishnaswamy4157 жыл бұрын
Damm,you are too good in explaining stuff :) Thanks!!! I am learning Android and i always look for depth understanding before getting into a concept.Your videos are really good.Are you a free lancer guy? :)
@Codetutor-DemystifyCoding7 жыл бұрын
Thanks for your kind words... I am glad that you are finding my videos useful. I am not a professional freelancer.. however I have done fair bit freelancing before... If you want to know bit more about me, you can visit my linkedIn profile here in.linkedin.com/in/anil-deshpande-18598b33. I also answer questions related to Android and many other related stuff on Quora. Probably you may find it helpful as well. This is my quora profile page www.quora.com/profile/Anil-V-Deshpande
@karthikkrishnaswamy4157 жыл бұрын
Thanks mate:) Even i am from bangalore.We should catch up some time.I have sent you fb and linkedin request.
@shmehdi016 жыл бұрын
runOnUIthread() is good idea or not?
@Codetutor-DemystifyCoding6 жыл бұрын
Let me put it this way... It is not the question of whether this good idea or not. It is the question of whether functionality needs it or not. If you want to update the UI then you have to use runOnUIthread(). There is no escaping from it. However if you have some thing long to to be processes that will block the UI thread then it is not good idea to do it on runOnUIthread(). Hope this helps.
@shahadsaleh64555 жыл бұрын
thank you.
@Codetutor-DemystifyCoding5 жыл бұрын
Hey Thanks.. Glad that you liked the videos. Feel free to explore other content on channel - visit playlist section. Hope you have subscribed.
@sarathimanivel18066 жыл бұрын
Very good explanation. I have one doubt. what is the difference between handler=new Handler(getApplicationContext().getMainLooper()); and handler=new Handler();
@Codetutor-DemystifyCoding6 жыл бұрын
No difference.. it's pretty much one and the same. By default Handler always gives handle to Main threads Looper. I just used getApplicationContext().getMainLooper() to make it explicitly clear to audience that I am interested in Handler to Main thread. That's all...
@sarathimanivel18066 жыл бұрын
OK suppose I create handler in the worker thread then this handler is run in main thread?
@Codetutor-DemystifyCoding6 жыл бұрын
I was tempted to answer this but let me say Try it see what happens? Just print Thread ids.. you should get your answer :-)
@suneelkumar-hm4kd6 жыл бұрын
hi sir, I was having a task like, where i have to insert/update A LOT OF DATA like 1000 rows with 80 columns each in the sqlite local DB, for that i was creating a thread.. in that thread i was creating a method like dbLogic(), the thing is after completion of the task i.e; insertion/updation completion i have to show an alert dialog, that alert dialog code i have written normally not in the thread..In some times the main problem causing is, the alert dialog is coming before only unless my another thread doesn't completed its work, i was trying to store 1000 data, in some times it was storing 200 data and the alert was coming,in some times it was storing 400 data alert was coming,in sometimes it was storing 550 or 600 or 650 the alert box was coming.. what i need is after successfully completion of the task only my main thread should execute. i heard that thread is an independent process... what to do please help me..
@Codetutor-DemystifyCoding6 жыл бұрын
I hope I have understood the question correctly. Looks like you can use a Loader. Loaders are used to carry out database operations (through a Content Provider) on a separate thread without blocking UI thread. It has a call back method then run's on UI thread once data base operations (on non ui thread) are completed. In this call back method you can write your code to trigger a alert dialog. Probably you will have to get started by creating a custom content provider. I suggest you watch these. 1. Content Provider basics: kzfaq.info/sun/PLfuE3hOAeWhb7kirY4rBtTLVF73jEXwG4 2. Creating Custom Content Provider: kzfaq.info/sun/PLfuE3hOAeWha-BtRXC2WRgZxxaUrDGAOi
@suneelkumar-hm4kd6 жыл бұрын
k thank u sir for ur reply i will try upon it ..
@Artsforkids4236 жыл бұрын
nice tutorial. can eplain with multithread with many process in on screen
@Codetutor-DemystifyCoding6 жыл бұрын
I suggest you watch the complete series : kzfaq.info/get/bejne/odZ2qtt7q7_Sf6M.html That is pretty comprehensive playlist. Based on what you learn from there, You should have good foundations (also with the help of bit self exploration as well) and be able to pretty much code for every possible scenario in Android multithreading.
@Artsforkids4236 жыл бұрын
ok
@user-pt7tv4 жыл бұрын
This guy is a fucking god, no joke!
@Codetutor-DemystifyCoding4 жыл бұрын
Hahaha... I would like to believe it is a compliment. Feel free to explore other content on channel. Visit playlist section. Hope you have subscribed.
@abhisheksengupta41596 жыл бұрын
Sir we can also use this : runOnUiThread(new Runnable() { @Override public void run() { // Our update task. } });
@Codetutor-DemystifyCoding6 жыл бұрын
Of course you can!! Just try it and see.
@abhisheksengupta41596 жыл бұрын
Yes it works :D
@Unknown-bd6fm7 жыл бұрын
Why you have passed looper in the Handler constructor? I read that thread automatically connected to the parent thread's looper. developer.android.com/reference/android/os/Handler.html#Handler()
@Codetutor-DemystifyCoding7 жыл бұрын
You are right. If you don't pass it, it would still work in exactly same fashion. I just wanted to explicitly make clear to the audience that the handler is working with UI looper. That's all.
@Unknown-bd6fm7 жыл бұрын
Ok thanks.
@TheRajmoney4 жыл бұрын
excellent explanation, but the audio is not good, the volume is low sometimes. thank you
@Codetutor-DemystifyCoding4 жыл бұрын
Thanks for the kind words. Yeah this video is one of the oldest when I didn't have proper gear. Now you will not find this kind of issues. So In the mean time you can explore remaining content from the channel. Visit the playlist section of the channel.
@vineetkumar86436 жыл бұрын
Please make videos on Adapter
@Codetutor-DemystifyCoding6 жыл бұрын
+Vineet Kumar which Adapter?
@rahultripathikanpur8 жыл бұрын
Code as per screen ,not working...
@Codetutor-DemystifyCoding8 жыл бұрын
+Rahul Tripathi Could you elaborate...I would love to explain
@SRIKANTH-ls9bm6 жыл бұрын
In asynchtask source code, handler is used to pass the message from mainthread to itself. is it Correct ? Parts of code is pasted , please clarify ? linke :github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/os/AsyncTask.java private Result postResult(Result result) { @SuppressWarnings("unchecked") Message message = getHandler().obtainMessage(MESSAGE_POST_RESULT, new AsyncTaskResult(this, result)); message.sendToTarget(); return result; } Since private static class InternalHandler extends Handler { public InternalHandler(Looper looper) { super(looper); } @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"}) @Override public void handleMessage(Message msg) { AsyncTaskResult result = (AsyncTaskResult) msg.obj; switch (msg.what) { case MESSAGE_POST_RESULT: // There is only one result result.mTask.finish(result.mData[0]); break; case MESSAGE_POST_PROGRESS: result.mTask.onProgressUpdate(result.mData); break; } } }
@fouzaialaa79627 жыл бұрын
you need a better mic !!
@Codetutor-DemystifyCoding7 жыл бұрын
+fouzai alaa yeah... I have changed my gear... In recent videos this issue is resolved... Please have a look at recent videos... And let me know the feedback
@Anilkumar-ec8sj6 жыл бұрын
Thanks for sharing the github helpful , Can you make a video on jobscheduler with example.
@Codetutor-DemystifyCoding6 жыл бұрын
This is something that I have on my mind for long time. Some time in future I will definitely be making a content on this topic. Thanks for commenting.
@boominathanarumugam55896 жыл бұрын
voice not clear sometimes various please solve this issues
@Codetutor-DemystifyCoding6 жыл бұрын
This is part of some of the earliest videos when channel was very new. I have changed the gear now. You will not see these kind of issues in latest videos. Check out the latest videos.
@boominathanarumugam55896 жыл бұрын
Thank you for your reply i have seened your videos daily because i am a Basic Android programmer your channel was helped to improve my self.. I want more videos for deep explanations in each concepts like Activity,Fragment,Service etc., Content Provider was to good
@boominathanarumugam55896 жыл бұрын
Voice not clear
@pseudoniem32937 жыл бұрын
Buy a decent microphone
@Codetutor-DemystifyCoding7 жыл бұрын
I agree...This is one of old videos... I have changed the gear now. I would like to believe that audio quality is much better in recent videos.