Android

182 Android Looper Example |

Launch Your First Android app with our TOP course at 82% OFF (24 hrs ONLY) HERE https://goo.gl/7veBXc “Learn How To Design +...



Launch Your First Android app with our TOP course at 82% OFF (24 hrs ONLY) HERE https://goo.gl/7veBXc
“Learn How To Design + Code A Complete App From Scratch To Playstore”
➨ https://www.youtube.com/watch?v=aWGGZCOHZ1k
-~-~~-~~~-~~-~-

This Android Tutorial video shows an example of Looper in Android. Looper is associated with a thread when you call Looper.prepare() and when you invoke Looper.loop() you process messages from the message queue of that thread. Main Thread can send Runnable or Message objects to background thread once the background thread has an associated Looper

OUR WEBSITE
http://slidenerd.com

OUR SOCIAL LINKS
https://www.facebook.com/groups/AndroidProgramming/
Follow us on
http://google.com/+slidenerd
http://facebook.com/slidenerd

http://pinterest.com/slidenerd

source

21 Replies to “182 Android Looper Example |”

  1. When i type inside the method OnClick, the system doesn't find "handler" while i write "myThread.handler.post…"

    I use buttonName.setOnClickListener(…) inside my OnCreate for handle the event OnClick, is this make a difference?

  2. Why do you have to create a new Handler in the run method and not in the constructor?? does that mean a new Handler must be created each time you post a Runnable on the worker thread? why?

  3. hi @slidenerd 

     
    does the main thread have a looper by default?
    I mean if the message is to be sent from other thread to main thread then do we have to write Load.prepare() in the main thread?
    I guess in the previous vid,you did not use Looper.prepare() in the main thread when the message was to be transferred from other thread to main thread.

  4. does the main thread have a looper by default?
    I mean if the message is to be sent from other thread to main thread then do we have to write Load.prepare() in the main thread?

  5. Hi vivz,
       Great video but how come we didn't have to create a looper in our main activity, so that our main class can have and manage a message queue?

  6. Looper.prepare ();
    handler= new handler();
    Looper.loop();

    Hey Vivz I a appreciate if you can share more light of how the (Looper) bind with the (handler)?

  7. One little hint on this – be sure to import the correct Handler class – the "import java.util.logging.Handler;" won't work, you want "import android.os.Handler;" – which was the second on my list to import.

  8. Hi Vivz, does the run() method run asynchronously of the main thread when you say myThread.start()? The reason I ask, say there was a long method call at the beginning of run() (like Thread.sleep(5000)), and then immediately after you call myThread.start() you were to call sendMessage(), would myThread.handler still be null and therefore result in NRE? So my follow up question, if that is the case, is there a way to test whether the thread is prepared to accept messages or not?

Beri komentar...