Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The issue lies in that you are not doing anything asynchronously here, and you should be. You should use an <a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="nofollow">AsyncTask</a> to do your work.</p> <p>Take a look at 'the 4 steps', as detailed here:</p> <p>The 4 steps</p> <p>When an asynchronous task is executed, the task goes through 4 steps:</p> <ol> <li>onPreExecute(), invoked on the UI thread immediately after the task is executed. This step is normally used to setup the task, for instance by showing a progress bar in the user interface.</li> <li>doInBackground(Params...), invoked on the background thread immediately after onPreExecute() finishes executing. This step is used to perform background computation that can take a long time. The parameters of the asynchronous task are passed to this step. The result of the computation must be returned by this step and will be passed back to the last step. This step can also use publishProgress(Progress...) to publish one or more units of progress. These values are published on the UI thread, in the onProgressUpdate(Progress...) step.</li> <li>onProgressUpdate(Progress...), invoked on the UI thread after a call to publishProgress(Progress...). The timing of the execution is undefined. This method is used to display any form of progress in the user interface while the background computation is still executing. For instance, it can be used to animate a progress bar or show logs in a text field.</li> <li>onPostExecute(Result), invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.</li> </ol> <p><strong>EDIT:</strong></p> <p>You can create an anonymous inner class to do your bidding, which may be similar to how you are creating your onClick handler. In your onClick do something like this:</p> <pre><code>//pseudo-code... onClick(View v, ...) { new AsyncTask&lt;Generic1, Generic2, Generic3&gt;() { protected void onPreExecute() { // do pre execute stuff... } protected Generic3 doInBackground(Generic1... params) { // do background stuff... } protected void onPostExecute(Generic3 result) { // do post execute stuff... } }.execute(); } </code></pre> <p>Don't forget to keep an eye on your generics here!</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