我有一个异步任务,它有一个非常简单的 doInbackground 和 onPostExecute。由于某些原因,我看到 PostExecute 方法被调用,并且在一些非常罕见的情况下,它被跳过调用。这导致我的应用程序出现意外流量。鉴于它大部分时间都被调用,我知道语法和参数是正确的。我也不会随时“取消”我的异步任务。那么,为什么会被跳过呢?
private class ViewStoppedAsync extends AsyncTask<Void, Void, Void> {
public ViewStoppedAsync() {
}
@Override
protected Void doInBackground(Void... params) {
Log.d(TAG, "ViewStopped - doInBackground");
releaseMediaPlayer();
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.d(TAG, "ViewStopped - onPostExecute");
super.onPostExecute(result);
<<my code>>
}
private void releaseMediaPlayer() {
Log.v(TAG, "releaseMediaPlayer()");
try {
videoView.stopPlayback();
} catch (Exception e) {
Log.i(TAG, "Handled: releaseMediaPlayer videoView.stopPlayback() - " + e, e);
}
if (mp != null) {
try {
mp.stop();
} catch (IllegalStateException e) {
Log.i(TAG, "Handled: releaseMediaPlayer mp.stop() - " + e, e);
} finally {
mp.release();
mp = null;
}
}
}
}