作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚开始使用线程,所以我有一个问题。在这种情况下,当我从 doInBackground() 调用 initOctoshape() 方法时,为什么会创建一个新线程(与后台线程不同)?谢谢!
public class PlayerActivity extends CustomActivity implements
ProblemListener{
public class PlayChannel extends AsyncTask<Channel, String, String> {
Channel channel;
PlayerActivity thisActivity;
@Override
protected String doInBackground(Channel... params) {
Thread.currentThread().getName();
channel=params[0];
thisActivity=channel.thisActivity;
initOctoshapeSystem(thisActivity);
return url;
}
}
public void initOctoshapeSystem(Activity thisActivity) {
os = OctoStatic.create(thisActivity, thisActivity, null);
os.setOctoshapeSystemListener(new OctoshapeSystemListener() {
@Override
public void onConnect() {
Thread.currentThread().getName();
mStreamPlayer = setupStream(OCTOLINK);
mStreamPlayer.requestPlay();
}
});
}
public StreamPlayer setupStream(final String stream) {
StreamPlayer sp = os.createStreamPlayer(stream);
sp.setListener(new StreamPlayerListener() {
@Override
public void gotUrl(String url) {
}
});
return sp;
}
}
最佳答案
AsyncTask
的 doInBackground(Params...)
方法始终在后台线程上执行,并且由于您调用了 initOctoshapeSystem(thisActivity);
从这个方法中,它也将在此后台线程上执行。这就是 AsyncTask
的行为。
所以,
a new thread (different from the background thread) gets created when I call the method initOctoshape() from doInBackground()
不正确。您对 initOctoshape()
的调用仅遵循驱动 doInBackground()
的线程。
关于java - AsyncTask 中的新线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40696718/
嘿。本周的一个教程,其中一个问题要求通过使用其他函数 formatLine 和 formatList 创建一个函数 formatLines,以格式化行列表。 我的代码是这样的; type Line =
我是一名优秀的程序员,十分优秀!