Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a few options:</p> <p>Define your own custom <code>AsyncTask</code> class and pass the <code>List</code> that you want filled into either its constructor:</p> <pre class="lang-java prettyprint-override"><code>class MyAsyncTask extends AsyncTask&lt;Void,Void,Void&gt; { private List&lt;LatLng&gt; mTheList; public MyAsyncTask(List&lt;LatLng&gt; theList) { mTheList = theList; } // fill the list in doInBackground() ... } // in your fragment MyAsyncTask task = new MyAsyncTask(theList); task.execute(); </code></pre> <p><strong>OR</strong> you can pass it as a parameter to the <code>execute()</code> method:</p> <pre><code>class MyAsyncTask extends AsyncTask&lt;List&lt;LatLng&gt;,Void,Void&gt; { public Void doInBackgroun(List&lt;LatLng&gt;...args { List&lt;LatLng&gt; theList = args[0]; // fill the list } } </code></pre> <p>Note that you can also pass the <code>Fragment</code> instance to the <code>execute()</code> method in the same way and then call the <code>getList()</code> method on that instance (I don't like this option).</p> <p>A better option would be:</p> <p>Create the list object in your custom <code>AsyncTask</code> class, and then return it back to the <code>Fragment</code> in the <code>postExecute()</code> method. You can do this by directly calling a method on the <code>Fragment</code> instance (that you'll get either via the constructor or as an argument to the <code>execute()</code> method) that accepts the list as a parameter. But, another (cleaner) way is to define an interface within your custom <code>AsyncTask</code> class for a callback method that accepts the filled list as an argument. Then your <code>Fragment</code> can implement this callback interface, add itself to the task as a "listener", and have the task call that inteface method, passing the filled list as an agrument inside the task's <code>postExecute()</code> method.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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