我有一个异步任务,它有一个非常简单的doInbackground和onPostExecute。 由于某些原因,我看到PostExecute方法被调用,并且在极少数情况下,它被调用被跳过。这导致我的应用程序出现意外流量。鉴于它大部分时间被调用,我知道语法和参数是正确的。我也不会随时“取消”我的asynctask。那么,为什么会被跳过?
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;
}
}
}
}