0

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.

Crash Report :

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)

And this error from this Fragment:

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

    }
}

}

furkanbzkurt
  • 296
  • 4
  • 14

2 Answers2

1

Your AsyncTask has no access to ui elements. Call this line from a runnable or try this.fpd.dismiss();.

The AsyncTask is not running in the apps main thread, which is the reason why you can not access them.

Antonio Vlasic
  • 337
  • 3
  • 15
1

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.

Highriser
  • 212
  • 2
  • 14