本文介绍了安卓:AsyncTask的,我的第一个任务还没有完成的时候启动等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code在我的主线程
Here's my code in my main thread
myAsyncRunnable mar = new myAsyncRunnable(GameActivity.this);
mar.execute("fire");
PhotoTask photoTask = new PhotoTask(camera,surfaceCamera,isPreview,holder,GameActivity.this);
photoTask.execute(null);
在myAsyncRunnable.fire()我有一个循环,改变gameActivity一个ImageView的10倍的图像。我想photoTask开始时的最后一个图像已更改
in myAsyncRunnable.fire() I have a loop that changes 10 times the image of an ImageView in gameActivity. I want the photoTask to start when the last image has been changed
@Override
protected Void doInBackground(String... params) {
fire();
return null;
}
public void fire() {
final ImageView image3 = (ImageView) gameactivity.findViewById(R.id.imageView3);
final int drawables[] = new int[] {R.drawable.fire1,R.drawable.fire2,R.drawable.fire3,R.drawable.fire4,R.drawable.fire5,R.drawable.fire6,R.drawable.fire7,R.drawable.fire8,R.drawable.fire9,R.drawable.fire10,R.drawable.fire11,R.drawable.fire12,R.drawable.fire13,R.drawable.fire14,R.drawable.fire15,R.drawable.fire16};
for (int i=0;i<drawables.length;i++) {
final int j=i;
Runnable runnable = new Runnable() {
@Override
public void run() {
image3.setImageResource(drawables[j]);
}
};
gameactivity.handler.postDelayed(runnable, 200*j);
}
}
但photoTask执行最后一次的形象已apperaed之前。这可能是由于postDelayed方法我都试过在方法onPostExecute()来执行photoTask但它没有工作,要么
But photoTask executes before the last image has apperaed. This is probably due to the postDelayed method and I have tried to execute photoTask in the method onPostExecute() but it didn't work either
推荐答案
将 photoTask.execute(NULL);
在 onPostExecute()
首的AsyncTask
这篇关于安卓:AsyncTask的,我的第一个任务还没有完成的时候启动等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!