Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Even though <a href="http://developer.android.com/reference/android/app/Service.html" rel="noreferrer">Service</a> is intended for background processing they run in the <strong>main thread</strong> .</p> <p>A short quote from the <a href="http://developer.android.com/guide/components/services.html" rel="noreferrer">documentation</a>:</p> <blockquote> <p>Caution: A services runs in the same process as the application in which it is declared and in the main thread of that application, by default. So, if your service performs intensive or blocking operations while the user interacts with an activity from the same application, the service will slow down activity performance. To avoid impacting application performance, you should start a new thread inside the service.</p> </blockquote> <p>The 'background processing' means that service has no user interface, it can run even if the user isn't directly interacting with the application. But all the background processing still happens in the main thread by default. </p> <p>So, how to solve it and get rid of the exception? As the documentation suggests you have to use a background thread. In your service you can use <code>AsyncTask</code> or create threads directly. But I guess <a href="https://developer.android.com/reference/android/app/IntentService.html" rel="noreferrer">IntentService</a> might be the most suitable in your case. <code>IntentService</code> processes requests in the background thread (so that's the kind of service you were looking for).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload