problems with fragment

0

I have an activity that controls a session and it also has many fragments that are the whole operation of the app, it turns out that I'm making a request for rest services in the fragment's onCreateView, and change fragments using the addToBackStack to save the History and be able to go back when I need, the problem is that I do not know why in some fragments when I execute a call to the server all these are done by means of threads, sometimes they are also executed at the same time called from previous screens. How can I solve this?

call to services:

in the onCreateView

fragment A

dialog = ProgressDialog.show(getActivity(), "", getString(R.string.progress), true);
Thread thread = new Thread() {
    @Override
    public void run() {

String token = LiveCookie.getInstance().getToken();

        oW = BusinessLogic.getOW(token,getActivity(),"TRANSFERENCIA");
        rW = BusinessLogic.getRW(token,getActivity());

        mHandler.post(complete);

    }
};

thread.start();

I navigate by fragment ABC in each one I make calls in the same way and when I pass between the fragment I use the following code:

Util.replaceFragment(new fragmentA(),getFragmentManager());

public static void replaceFragment (Fragment fragment,FragmentManager manager){
        String backStateName = fragment.getClass().getName();

            FragmentTransaction ft = manager.beginTransaction();
            ft.replace(R.id.content_frame, fragment,backStateName);
            ft.addToBackStack(backStateName);
            ft.commit();
    }

and in the FragmentC when I call the service, the FragmentA plains that are onCreateView are also made at the same time, making two requests at the same time, and this gives me errors and I just want to make the request I need in the FRagmentC

    
asked by julian david 06.12.2017 в 23:54
source

0 answers