Android: How to work with background thread?
public Runnable NameOfRunnable = new Runnable(){ @Override public void run() { while (true) { // TODO add code to refresh in background try { Thread.sleep(1000);// sleeps 1 second } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }};
now start this with
Thread name = new Thread(NameOfRunnable); name.start();
How to work with Background Thread.
Note:
Do not work with UI with this background thread.AsyncTask.execute(new Runnable() { @Override public void run() { //TODO background code }});
Hope this would help you.