runonuithread没有从asynctask doinbackground调用

时间:2014-03-12 13:38:08

标签: android android-fragments android-asynctask

我有一个progressbarsfragment,它们会添加到asynctask中,并在progressbar中更新。现在我想在完成后替换并重置asynctask。我开始使用新的UI来获取其他相关内容,并更新其postexecute中的//my asynctask to update the progressbar @Override protected Integer doInBackground(String... arg0) { // TODO Auto-generated method stub // display the images in now playing while (ScheduleManager.isScheduleRunning) { Iterator iterator = nowPlayingMediaSet.entrySet().iterator(); // set images on now playing for (int i = 0; i < btnImgNowPlaying.length && iterator.hasNext(); ++i) { Map.Entry mEntry = (Map.Entry) iterator.next(); Show mShowNowPlaying = (Show) mEntry.getKey(); // get show status mProgressStatus[i] = ScheduleManager .getCurrentPlayingShowStatus(mShowNowPlaying); if (mProgressStatus[i] > 100) { this.newSchedule = (ChannelSchedule) mEntry .getValue(); // get now playing show and replace it this.newShow = ScheduleManager .getNowPlayingShow(newSchedule.getListOfShows()); iterator.remove(); final int index = i; FragmentTvGuide.GetParentActivity().runOnUiThread( new Runnable() { @Override public void run() { // TODO Auto-generated method stub new ScheduleListnerTask( btnImgNowPlaying[index]) .execute(newShow .getShowThumb()); //does not get invoked } }); this.newShowAdded = true; } // Update the progress bar } if (newShowAdded){ this.nowPlayingMediaSet.put(newShow, newSchedule); newShowAdded = false; } publishProgress(mProgressStatus); // sleep 1 second to show the progress try { Thread.sleep(20000); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } //this is how get the parentactivity from fragment //in onactivitycreated context = getActivity(); //context is static public static Activity GetParentActivity(){ return (Activity) context; } 。我就是这样做的:

asynctask

我不知道这里出了什么问题?有什么想法吗?

修改

这是我试图调用的public class ScheduleListnerTask extends AsyncTask<String, Void, Bitmap> { ImageButton btnImage; public ScheduleListnerTask(ImageButton btnImage){ this.btnImage = btnImage; } @Override protected Bitmap doInBackground(String... params) { // TODO Auto-generated method stub String urldisplay = params[0]; Bitmap mIcon11 = null; ImageLoader iLoader = ImageLoader.getInstance(); try { mIcon11 = iLoader.loadImageSync(urldisplay); } catch (Exception e) { Log.e("Error", "image download error"); Log.e("Error", e.getMessage()); e.printStackTrace(); } return mIcon11; } @Override protected void onPostExecute(Bitmap result) { // TODO Auto-generated method stub btnImage.setImageBitmap(result); } }

{{1}}

1 个答案:

答案 0 :(得分:1)

我想你忘记在新任务上调用execute()了... 编辑:好的抱歉,你没有......

然而,我发现在另一个异步任务中通过在UIthread上运行它来开始一个新的asynctask一点点...我为什么不在此时发布进度,并从onprogressupdated开始新的任务...... ?