Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is looper in android ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 146
    Comment on it

    We know that a normal thread doesn't maintain any message queue they runs one after another but in case we want to performs more thread then we used looper class to maintains all runnable messages in queue and runs them one by one .

    Here is an example of looper class :

    class MyLooper extends Thread {
        private Handler mHandler;
    
        @Override
        public void run() {
            Looper.prepare();
            // Initialize the  current thread as a looper that is used to processed message queue.
    
            mHandler = new Handler() {
                @Override
                public void handleMessage(Message msgs) {
                    //your message here
                }
            };
    
            // Run the message queue or create loop in this thread.
            Looper.loop();
        }
    }

     

    Note : If we are not using any looper here then it will throw exception like thread has not called Looper.prepare() .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: