請參閱下面的代碼。無法從UI中的URL製作精靈Andengine Android中的線程
Activity ac= (Activity)cxt;
ac.runOnUiThread(new Runnable() {
@Override
public void run() {
load();
}
});
這是構造在那裏我調用一個函數來從URL加載一個精靈。功能如下
private void load()
{
if(isInternetOn()){
try {
ITexture mTexture = new BitmapTexture(mEngine.getTextureManager(), new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
URL url = new URL("http://tenlogix.com/cupcakemania/Ads/burgermaker.png");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(input);
return in;
}
});
mTexture.load();
MyImageFromWeb = TextureRegionFactory.extractFromTexture(mTexture);
} catch (IOException e) {
Log.d("TenlogixAds"," "+e);
}
AdSprite = new Sprite(0, 0, MyImageFromWeb, mEngine.getVertexBufferObjectManager());
}
else{
Log.d("TenlogixAds"," No Internet Connection Detected.. ");
AdSprite = null;
}
}
的問題是,如果我現在調用加載功能在UI線程,但是當我把它在UI線程其未加載圖像加載。
在UI線程中調用它非常重要,因爲我想要執行此任務是背景導致遊戲運行問題。
我也試過AsyncTask,但是我用UI線程描述的問題與異步任務是一樣的。
任何人都可以幫助我解決這個問題嗎?
我想從網絡加載圖像,我希望它在後臺加載,導致遊戲正在播放任何延遲或問題。
使用異步任務的兄弟,因爲當它被稱爲UI線程沒有恢復call.But異步答覆你,如果它得到來自以前呼叫的迴應。 –