title: How to start a new Thread in a service?
body: <p>I am developing an Android app and I am doing some heavy work (bringing data from an online web page and parsing it to store in database) in a service. Currently, it is taking about 20+ mins and for this time my UI is stuck. I was thinking of using a thread in service so my UI doesn't get stuck but it is giving error. I am using the following code:</p>
  
  <pre><code>Thread thread = new Thread()
  {
        @Override
        public void run() {
            try {
                while(true) {
                    sleep(1000);
                    Toast.makeText(getBaseContext(), "Running Thread...", Toast.LENGTH_LONG).show();
                }
            } catch (InterruptedException e) {
             Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    };
  
  thread.start();
  </code></pre>
  
  <p>This simple code is giving run time error. Even If I take out the while loop, it is still not working. 
  Please, can any one tell me what mistake I am doing. Apparently, I copied this code directly from an e-book. It is suppose to work but its not. </p>