Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>AsyncTask</code> class can be thought of as a very convenient threading mechanism. It gives you a few tools that you can use that simple Java threads simply don't have such as on cancel cleanup operations. You don't have to do any UI in the background. You could simply execute one by writing one as an anonymous class like this: </p> <pre><code> new AsyncTask&lt;Integer, Void, Void&gt;(){ @Override protected Void doInBackground(Integer... params) { // **Code** return null; } }.execute(1, 2, 3, 4, 5); </code></pre> <p>It will execute whatever you put in <code>doInBackground</code> on a background thread with the given parameters. Likewise, you can simply use <code>Void</code> and execute with no parameters.</p> <p>The only advantage I could think of executing a thread this way would be to aid in future maintenance. There might be a case where you want to modify certain things that are required to be on the UI thread, in which case you would override the other methods. Other cases would be you simply don't do the action enough to justify writing out another class, so just create one on the fly and be done with it.</p> <p><strong>EDIT:</strong></p> <p>To answer #3: they're effectively the same. The <code>Void</code> object is a Java object just like anything else. You're not using <code>Void</code>, so what you use in it's place doesn't matter. It's just the <code>AsyncTask</code> contract requires three class types to be passed in, and by default they're <code>Object</code> which is the baseline class of everything.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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