IllegalStateException asynctask-onPostExecute [英] IllegalStateException asynctask - onPostExecute

查看:81
本文介绍了IllegalStateException asynctask-onPostExecute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了我的应用.它在我的设备上运行正常.但是我在游戏机上得到了一些崩溃报告.但是我不知道该如何处理.我知道问题是进度对话框.我应该怎么办?预先感谢.

I published my app. it is working smoothly on my device. But I get some crash reports on play console. But I couldn't figure out how to handle it. I know the problem is progress dialog. What should I do? Thanks in advance.

崩溃报告:

java.lang.IllegalStateException: 
  at android.app.FragmentManagerImpl.checkStateLoss (FragmentManager.java:1328)
  at android.app.FragmentManagerImpl.enqueueAction (FragmentManager.java:1346)
  at android.app.BackStackRecord.commitInternal (BackStackRecord.java:729)
  at android.app.BackStackRecord.commit (BackStackRecord.java:705)
  at android.app.DialogFragment.dismissInternal (DialogFragment.java:292)
  at android.app.DialogFragment.dismiss (DialogFragment.java:258)
  at com.example.genesis.policeradiostream.TopFeedsFragment$Listeleme.onPostExecute (TopFeedsFragment.java:172) 
  at com.example.genesis.policeradiostream.TopFeedsFragment$Listeleme.onPostExecute (TopFeedsFragment.java:95)
  at android.os.AsyncTask.finish (AsyncTask.java:636)
  at android.os.AsyncTask.access$500 (AsyncTask.java:177)
  at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:653)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:153)
  at android.app.ActivityThread.main (ActivityThread.java:5254)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:902)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:697)

此片段中的错误:

公共类TopFeedsFragment扩展了片段{

public class TopFeedsFragment extends Fragment {

public static  RadiosListAdapter adapter_3;
protected View mView;
FlipProgressDialog fpd = new FlipProgressDialog();
public TopFeedsFragment() {
}


@Override
public void onPause() {
    super.onPause();
    fpd.dismiss();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =  inflater.inflate(R.layout.fragment_top_feeds, container, false);
    this.mView = view;

    List<Integer> imageList = new ArrayList<Integer>();
    imageList.add(R.drawable.img_progress_dialog_red_4);
    imageList.add(R.drawable.img_progress_dialog_blue_4);

    fpd.setImageList(imageList);
    fpd.setCanceledOnTouchOutside(true);
    fpd.setBackgroundColor(Color.TRANSPARENT);
    fpd.setImageSize(600);
    fpd.setOrientation("rotationY");
    fpd.setDuration(400);


    new Runnable() {
        @Override
        public void run() {
            new Listeleme().execute();
        }
    }.run();

    return view;
}


private class Listeleme extends AsyncTask<Void,Void,Void> // LINE 95
{

    String URL="...";

    @Override
    protected  void onPreExecute()
    {
        super.onPreExecute();
        fpd.show(getActivity().getFragmentManager(),"");

    }
    @Override
    protected Void doInBackground(Void... params) {

        //...
      //Some Jsoup
        //...
        return null;
    }
    @Override
    protected void onPostExecute(Void avoid)
    {

        ListView listView_top = (ListView) mView.findViewById(R.id.listview_topfeeds);
        if (getActivity()!= null) {
            adapter_3 = new RadiosListAdapter(getActivity(), radioname, listener_number);
            listView_top.setAdapter(adapter_3);
        }


        listView_top.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                PlayRadioFragment fragment= new PlayRadioFragment();
                Bundle bundle= new Bundle();
               //...
            }
        });

        fpd.dismiss();   //LINE 172

    }
}

}

推荐答案

问题是您要关闭onPostExecute中的对话框.基本活动可能已经消失了.您必须检查活动是否仍然存在.这就是为什么您会收到一个IllegalStateException的原因.活动的状态在消失后即被保存,您要在以后关闭该对话框,否则将无法进行.

The problem is that you are dismissing a dialog in the onPostExecute. The underlying activity could already be gone. You have to check if the activity is still there. That's why you get an IllegalStateException. The state of the activity was saved when it disappeared and you wanted to dismiss the dialog afterwards, this won't work.

这篇关于IllegalStateException asynctask-onPostExecute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆