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

    1. private Handler myHandler = new Handler();

    Step :-2 Create the Runnable Thread.

    1. private Runnable myRunnableThread = new Runnable()
    2. {
    3. public void run()
    4. {
    5. try {
    6. /*Here you can perform the task you want to play at the backgroubd*/
    7. Log.d("MyMessage", "I am on thr running thread");
    8. }
    9. catch (Exception ex)
    10. {
    11. finish();
    12. }
    13. }
    14. };

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

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

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: