Explained - Android UI thread/main thread

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

Комментарии • 64

  • @fritzauguste6669
    @fritzauguste6669 3 года назад +1

    Wow i am so glad i landed on this explanation first, very clear.

  • @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...

  • @freshfast6197
    @freshfast6197 6 лет назад

    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

  • @aviksutar
    @aviksutar 6 лет назад +3

    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 :-)

  • @prashantkamble898
    @prashantkamble898 7 лет назад +6

    Very best explanation. Very easy to understand. Thank you

    • @baghi3hi219
      @baghi3hi219 4 года назад

      This is theqawedwaedf original comment.

  • @hafizdwp
    @hafizdwp 7 лет назад +2

    BEST EXPLANATION! thank you very much

  • @Quancept
    @Quancept 5 лет назад +1

    That was a very good explanation. Thanks!

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  5 лет назад +1

      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.

  • @antoneltonij8362
    @antoneltonij8362 4 года назад

    Thank!
    Nice illustration, nice explanation

  • @karthikvs2152
    @karthikvs2152 3 года назад

    accurate and easy to understand . thank you so much sir

  • @priyadharshinik1088
    @priyadharshinik1088 5 лет назад +1

    Awesome tutorials.. Keep doing the same sir... 🤝🏻

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  5 лет назад +1

      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.

  • @eduardocardozo6737
    @eduardocardozo6737 3 года назад

    Simple and clear.

  • @be.happyfaces
    @be.happyfaces 7 лет назад +1

    Nice explanation.
    Thank you sir

  • @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

  • @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

  • @medgabsent9615
    @medgabsent9615 8 лет назад

    subscribe , because explaining using demos much easy to understand
    good work !!.

  • @MuhammadAli_hub
    @MuhammadAli_hub 4 года назад

    Short and at the same time Comprehensive....

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  4 года назад

      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 лет назад +1

      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.

  • @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.

  • @arjunkhanna1803
    @arjunkhanna1803 4 года назад

    explaination is very good but could you please improve the voice quality?

  • @sana_r_1212
    @sana_r_1212 6 лет назад

    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  6 лет назад

      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.

  • @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.

  • @StereoWorld
    @StereoWorld 3 года назад +1

    Etv music in the intro

  • @jaitpurhighschool7078
    @jaitpurhighschool7078 5 лет назад

    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  5 лет назад

      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.

  • @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.

  • @agbedesamueld
    @agbedesamueld 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?

  • @OmPrakash-hs3tw
    @OmPrakash-hs3tw 7 лет назад

    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  7 лет назад

      Hi Om, Parcelable has been covered on Codetutor previously. Please visit: ruclips.net/p/PLfuE3hOAeWhbtEnCB0-vuF2hSmwGAAeea

  • @vikashgauravvkg
    @vikashgauravvkg 7 лет назад

    Awesome explanation

  • @revansiddappakalshetty4827
    @revansiddappakalshetty4827 7 лет назад +1

    very nicely explained

  • @vinodkamble3818
    @vinodkamble3818 7 лет назад

    Nice explanation

  • @karthikkrishnaswamy415
    @karthikkrishnaswamy415 8 лет назад +1

    Very well explained..

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  8 лет назад +1

      Thanks...Stay tuned as I shall be publishing videos on Looper and Handler to deal with slightly complicated scenarios...

  • @prashantkamble898
    @prashantkamble898 7 лет назад

    Please explain me what is role of runOnUIThread method in android?

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  7 лет назад +3

      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.

  • @forpayonerr1149
    @forpayonerr1149 6 лет назад

    great explanation

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  5 лет назад

      Feel free to explore other content on playlist section of the channel. Hope you have subscribed.

  • @zahidali-pv8vp
    @zahidali-pv8vp 8 лет назад

    Nice tutorial thanks sir. sir please also deliver tutorial on process

    • @Codetutor-DemystifyCoding
      @Codetutor-DemystifyCoding  8 лет назад

      Thanks... stay tuned.. one of these days you may get the topic that you suggested...cheers.. happy coding..

  • @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.

  • @rajivraghu9857
    @rajivraghu9857 7 лет назад

    Thanks :)

  • @ingenieurinformatik2037
    @ingenieurinformatik2037 6 лет назад

    Very bad accent.