Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask will not stop running even after onPostExecute completes and blocks activity from being GC'd
    primarykey
    data
    text
    <p>My activity does a lot of network I/O, so I start an AsyncTask (since you can not do network I/O on the UI thread) to accomplish this. My problem is that the when I call finish() to exit my application, the app is never garbage collected and continues to run in the background. I am assuming (perhaps incorrectly) that the task is never GC'd because the AsyncTasks are still running as the Eclipse debug window shows me. I have read everything I can find on this and it appears to be a problem without a solution.</p> <p>Here are the details:</p> <p>in OnCreate I create a MessageHandler as follows:</p> <pre><code>mMessageHandler = new Handler() { @Override public synchronized void handleMessage(Message msg) { switch( (int)msg.arg1) { case kMessageDoSomething: doSomething(); break; . . </code></pre> <p>I have a class for each AsyncTask, for example in myAsyncTask.java</p> <pre><code>public class myAsyncTask extends AsyncTask&lt;Void, Object, Object&gt; { @Override protected Object doInBackground(Void... params) { doSomeNetworkIO(); return null; } @Override protected void onPostExecute(Object result) { super.onPostExecute( result ); msg = new Message(); msg.arg1 = MyActivity.getInstance().kMessageDoSomething; MyActivity.getInstance().mMessageHandler.sendMessage( msg ); } </code></pre> <p>and back in myActivity</p> <pre><code>new myAsyncTask().execute(); </code></pre> <p>in the method doSomthing() I check the AsyncTask.Status of myAsyncTask and it is FINISHED, yet the debugger still shows the task as running and when I call finish() myActivity never terminates unless I use AppKiller to kill it manually.</p> <p>My real question here is, am I chasing a red herring? that is does the presence of running threads stop the activity from being garbage collected?</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. 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