Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create Handler in Android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 144
    Comment on it

    If you want to create handler , here is the code snippet that can help you out.

    Step :-1 Create the object for Handler.

    private Handler myHandler = new Handler();
    

    Step :-2 Create the Runnable Thread.

     private Runnable myRunnableThread = new Runnable()
          {
            public void run()
               {
                 try {
                      /*Here you can perform the task you want to play at the backgroubd*/
                      Log.d("MyMessage", "I am on thr running thread");
                     }
                  catch (Exception ex)
                     {
                       finish();
                     }
                 }
            };
    

    Step 3:-Now you can call the handler where you want to run the thread.

        /*call postDelayed method of Handler that takes 2 argument "runnable thread" and
          "milliseconds" after which you want to run the thread */
    
    myHandler.postDelayed(myRunnableThread, 1);
    
    

 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: