over 9 years ago
If you want to create handler , here is the code snippet that can help you out.
Step :-1 Create the object for 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();
- }
- }
- };
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);
/*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)