Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Consider this Task (where R.id.test refers to a valid view in my activity's layout):</p> <pre><code>public class LongTaskTest extends AsyncTask&lt;Void, Void, Void&gt;{ private WeakReference&lt;Activity&gt; mActivity; public LongTaskTest(Activity a){ mActivity = new WeakReference&lt;Activity&gt;(a); } @Override protected Void doInBackground(Void... params) { LogUtil.d("LongTaskTest.doInBackground()"); SystemClock.sleep(5*60*1000); LogUtil.d("mActivity.get()==null " + (mActivity.get()==null)); LogUtil.d("mActivity.get().findViewById(R.id.frame)==null " + (mActivity.get().findViewById(R.id.test)==null)); return null; } } </code></pre> <p>If I run this task from an Activity's onCreate like so:</p> <pre><code>public class Main extends Activity { @Override public void onCreate(Bundle state) { super.onCreate(state); setContentView(R.layout.testlayout); new LongTaskTest(this).execute(); finish(); } } </code></pre> <p>No matter how long I sleep the background thread, my log always shows:</p> <pre><code>LongTaskTest.doInBackground() mActivity.get()==null false mActivity.get().findViewById(R.id.frame)==null false </code></pre> <p>Which is to say that the activity and its views appear to stay alive (even if I manually issue GCs via DDMS). If I had more time I'd look at a memory dump, but otherwise I don't really know <em>why</em> this is the case ... but in answer to your questions it appears that:</p> <ul> <li>Does it silently fail? No </li> <li>Does it produce any exception? No</li> <li>Will the user be notified that something has gone wrong? No</li> </ul>
    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. 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