Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: thread interruption callback
    text
    copied!<p>Situation: activity performs some actions in background <a href="http://developer.android.com/reference/java/lang/Thread.html" rel="nofollow">Thread</a>. When activity is closed, android kills thread too. I want to write thread stop into log. Is there any callbacks ? (overriding interrupt() and destroy() not works) Or i should use <a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="nofollow">AsyncTask</a> instead ?</p> <p><strong>UPD:</strong> Thread code</p> <pre><code>private class InternalReader extends Thread { @Override public void run() { final int size = mReader.getDataSize(); final int blockSize = 10240; int offset = 0; TextFileCacher.DataBlock db = new TextFileCacher.DataBlock(); db.data = new char[blockSize]; int read = mReader.readString(offset, db.data, -1); mListener.onRenderStarted(); mListener.onRenderReady(); while (read &gt; 0){ db.size = read; mCacher.processData(db); offset+=read; mListener.onProgress(offset/size); read = mReader.readString(offset, db.data, -1); } mListener.onRenderReady(); } } </code></pre> <p>AsyncTask code</p> <pre><code>private class InternalReader extends AsyncTask&lt;Void, Void, Void&gt; { @Override protected Void doInBackground(Void... arg0) { final int size = mReader.getDataSize(); final int blockSize = 10240; int offset = 0; TextFileCacher.DataBlock db = new TextFileCacher.DataBlock(); db.data = new char[blockSize]; int read = mReader.readString(offset, db.data, -1); mListener.onRenderStarted(); mListener.onRenderReady(); while (read &gt; 0){ db.size = read; mCacher.processData(db); offset+=read; mListener.onProgress(offset/size); read = mReader.readString(offset, db.data, -1); } mListener.onRenderReady(); return null; } } </code></pre> <p>Initialisation</p> <pre><code>(new InternalReader()).start(); </code></pre> <p>and </p> <pre><code>(new InternalReader()).execute(); </code></pre>
 

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