0

我正在尝试从 AsyncTask 重新加载 ListFragment,如下所示:

    //set the string of the kitchen banner depending on the 
@Override
protected void onProgressUpdate(Integer... values) {
  super.onProgressUpdate(values);
    RequestNewTopBannerFragment requestNewTopBannerFragment = new RequestNewTopBannerFragment();
    Bundle argsBanner = new Bundle();
    argsBanner.putString(RequestNewTopBannerFragment.ARG_KEY_BANNER_TEXT_STR, crrentTopBannerString);//this.currentRequestType ContractFoodServices.NEW_REQUEST_CONST;
    requestNewTopBannerFragment.setArguments(argsBanner);


    transaction.replace(R.id.fragment_container_top_banner_kitchen, requestNewTopBannerFragment) ;

    transaction.addToBackStack(null);
    transaction.commit();//LIGHT TIGER : commitAllowingStateLoss()
}

但是虽然我在函数“onProgressUpdate”中执行此操作,但我得到异常“IllegalStateException:在 onSaveInstanceState 之后无法执行此操作”当然如果我将函数“commit”更改为“commitAllowingStateLoss”,它会显示相同的异常,并且在同时,Fragment 不会一直重新加载,有时它可以工作,而另一些则不能。

我尝试使用另一种方式从线程重新加载 ListFragment,所以我尝试了以下代码:

runOnUiThread(new Runnable() {
 public void run()   {

                RequestNewTopBannerFragment requestNewTopBannerFragment = new RequestNewTopBannerFragment();
    Bundle argsBanner = new Bundle();
    argsBanner.putString(RequestNewTopBannerFragment.ARG_KEY_BANNER_TEXT_STR, crrentTopBannerString);//this.currentRequestType ContractFoodServices.NEW_REQUEST_CONST;
    requestNewTopBannerFragment.setArguments(argsBanner);


    transaction.replace(R.id.fragment_container_top_banner_kitchen, requestNewTopBannerFragment) ;

    transaction.addToBackStack(null);
    transaction.commit();//LIGHT TIGER : commitAllowingStateLoss() 
                }
        });

但它也没有工作,并显示相同的异常,那么能够从“AsyncTask”始终重新加载 FragmentList 的解决方案是什么

提前致谢

4

0 回答 0