diff options
| -rw-r--r-- | docs/html/guide/components/services.jd | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/docs/html/guide/components/services.jd b/docs/html/guide/components/services.jd index 8da1694b77b5..4053769995b3 100644 --- a/docs/html/guide/components/services.jd +++ b/docs/html/guide/components/services.jd @@ -336,14 +336,11 @@ public class HelloIntentService extends IntentService { protected void onHandleIntent(Intent intent) { // Normally we would do some work here, like download a file. // For our sample, we just sleep for 5 seconds. - long endTime = System.currentTimeMillis() + 5*1000; - while (System.currentTimeMillis() < endTime) { - synchronized (this) { - try { - wait(endTime - System.currentTimeMillis()); - } catch (Exception e) { - } - } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + // Restore interrupt status. + Thread.currentThread().interrupt(); } } } @@ -405,14 +402,11 @@ public class HelloService extends Service { public void handleMessage(Message msg) { // Normally we would do some work here, like download a file. // For our sample, we just sleep for 5 seconds. - long endTime = System.currentTimeMillis() + 5*1000; - while (System.currentTimeMillis() < endTime) { - synchronized (this) { - try { - wait(endTime - System.currentTimeMillis()); - } catch (Exception e) { - } - } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + // Restore interrupt status. + Thread.currentThread().interrupt(); } // Stop the service using the startId, so that we don't stop // the service in the middle of handling another job |