Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>What do i have to write into onPostExecute and the Activity grab the string from doInBackground?</p> </blockquote> <p>When you are using <code>AsyncTask</code> then you can update your <code>UI</code> only on <code>onProgressUpdate</code> and <code>onPostExecute</code> method. <br><br>Your <code>doInBackground()</code> method returns some data and these data is going to <code>onPostExecute</code> method(it depends also how your generic are declared). <br><br>Generally, there is no another approaches how to do it.</p> <p>You meant this:</p> <pre><code>AsyncTask a = new AsyncTask(Context); a.execute(Input); </code></pre> <p>First means that your constructor looks like</p> <pre><code>public MyAsync(Context c) { this.c = c; } </code></pre> <p>Second means that you declared your first generic type(assumption Input param is <code>String</code>) as</p> <pre><code>private class MyAsync extends AsyncTask&lt;String, Void, String&gt; { //... } </code></pre> <p><br>And you want to update <code>UI</code> with <code>String</code> that returns <code>doInBackground()</code> method and merely place is <code>onPostExecute</code> method with <code>IN</code> parameter <code>String</code> that returns <code>doInBackground()</code>.<br><br></p> <pre><code>protected void onPostExecute(String stringReturnedFromDoInBackground) { // some work } </code></pre> <p><br>So if you want to do it in different way, change your application logic and use for example <code>ResultReceiver</code> with <code>IntentService</code>.</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