Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the <a href="http://developer.android.com/guide/components/aidl.html" rel="nofollow">AIDL docs</a>:</p> <blockquote> <p>By default, <strong>RPC calls are synchronous</strong>. If you know that the service takes more than a few milliseconds to complete a request, you should not call it from the activity's main thread, because it might hang the application (Android might display an "Application is Not Responding" dialog)—you should usually call them from a separate thread in the client.</p> </blockquote> <p>When you call a method on your <code>IBinder</code> instance to do the HTTP request, the calling thread (in this case, probably the UI thread) is blocking and triggering the exception. To take advantage of the service's background thread, you should send work to it through an <code>Intent</code>.</p> <p>Depending on your requirements, an <code>IntentService</code> or an <code>AsyncTask</code> may be a better approach.</p> <p>If you use an <code>IntentService</code> (even in the same app process), the <code>Intent</code> will be handled on a background thread. You will need a mechanism for sending results back to the client (your <code>Activity</code> in this case); I've used a <code>BroadcastReceiver</code> for this purpose.</p> <p>If your service only makes short HTTP requests and returns the results to an <code>Activity</code>, then an <code>AsyncTask</code> will be much simpler to implement.</p> <p><strong>EDIT</strong>:</p> <p>I think there is some confusion about how Android handles threads. The problem with your architecture is that you're calling a long-running method on an <code>IBinder</code> object, and you're calling it from the UI thread of your app. This type of RPC call <strong>will block</strong> while the method runs and will cause the exception that you're describing.</p> <p>The recommended way to send long-running work to a service is through an <code>Intent</code>. As I said earlier, an <a href="http://developer.android.com/reference/android/app/IntentService.html" rel="nofollow"><code>IntentService</code></a> will handle its intents in a background thread automatically and doesn't need a separate process. (A separate process is generally needed only if the service is likely to crash and you don't want it to bring down the app.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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