如何在 activity 完成后释放线程?

how can i release thread with activity finish?

抱歉我的英语不好:)。 在我的应用程序中,有一个 VideoView 可以播放视频(m3u8)。 在这个VideoViewactivity中,我使用ThreadExecutorService(newCachedThreadPool)来获取游戏URL等信息。 当我想回到上一个 activity 时,我会做这样的事情:

@Override
public void onDestroy() {
    super.onDestroy();
    if (videoView != null) {
        videoView.stopPlayback();
        videoView = null;
    }
    if (executor != null) {
        executor.shutdownNow();
        executor = null;
    }
}

这里是Runnable

private Runnable changeSeekBar = new Runnable() {
@Override
public void run() {
    // TODO Auto-generated method stub
    try {
        while (seekBarAutoFlag) {
            if (null != videoPlay.this.videoView&& videoPlay.this.videoView.isPlaying()) {
                video_seekBar.setProgress((int) videoView.getCurrentPosition());
            }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
};

执行者是这样的:

executor.execute(changeSeekBar);

这是错误信息 enter image description here

最后,我用EventBus代替Thread+Handler,成功了

这里是 EventBus github:https://github.com/greenrobot/EventBus

非常感谢您的帮助:)