AsyncTask and Fragments

0

Hello, I'm a newbie in development and I have some questions.

I have to implement a new layout, where:

  • Converted activities that load data into fragments;
  • In a new activity the graphic fragment is at the top and what loads the list is below, dividing the screen.
  • MetaActivity: converted to fragment, brings a ListView, clicking on a record goes to the activity

    - FragmentsPeriods PreviousActivity

    ---- (Fragment Top) PeriodGraphActivity (converted to fragment)

    ---- (Fragment Bottom) PeriodActivity (converted to fragment) loads the data into an ArrayList with the data, within the asynchronous method

    The reason that I converted them instead of creating in a new class with the fragment nomenclature is because Async does not execute the routine, it only works in this class ...

    The PeriodActivity class currently in the onActivityCreated method loads the targets in the webservice's listview from AsyncTask and saves them to a "global" variable:

    ...
    callBack = new AsyncCallBack() {
      public void onTesting(Object res) {
        ...
        Intent listaMetas = getActivity().getIntent();
        Bundle extras = new Bundle();
        extras.putSerializable("ListaPeriodo", metas);
        listaMetas.putExtras(extras);
      }
    }
    

    The Class PeriodGraphActivity (Loads an AndroidPlot with the data generated in the PeriodoActivity fragment and stored in the serializable "PeriodicList") // in the onStart () method

    Intent listaMetas = getActivity().getIntent(); 
    ArrayList<Cenario1> teste = new ArrayList<Cenario1>();
    metas =  (ArrayList<Cenario1>) getActivity().getIntent().getSerializable("ListaPeriodo"); // retorna nulo
    

    - > My big question, is it possible to choose the moment or when the asynchronous method is executed?

    - > Is it good practice to load asynchronous data into fragments?

    Fragments lifecicle monitor android monitor and activity:

    ...
    03-31 09:32:03.678 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosMetaActivity onCreateView (not implemented)
    03-31 09:32:03.686 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosMetaActivity onCreateView (not implemented)
    03-31 09:32:03.780 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosMetaActivity onCreateView (not implemented)
    03-31 09:32:13.717 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosMetaActivity onPause (not implemented)
    03-31 09:32:13.780 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosPeriodosAnterioresActivity onStart (not implemented)
    03-31 09:32:13.780 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoGraphActivity onCreate 
    03-31 09:32:13.780 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoGraphActivity onCreateView 
    03-31 09:32:13.842 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosPeriodosAnterioresActivity onStart (not implemented)
    03-31 09:32:13.842 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoActivity onCreate
    03-31 09:32:13.842 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoActivity onCreateView
    03-31 09:32:13.866 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosPeriodosAnterioresActivity onCreate
    03-31 09:32:13.866 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoGraphActivity onActivityCreated
    03-31 09:32:13.866 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoActivity onActivityCreated - (chamada para o metodo assíncrono)
    03-31 09:32:13.951 25105-25105/com.amend.cockpit D/LifeCicle: FragmentosPeriodosAnterioresActivity onStart
    03-31 09:32:13.951 25105-25174/com.amend.cockpit D/LifeCicle: AsyncBlock doInBackground
    03-31 09:32:13.951 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoGraphActivity onStart - (Testativa de recuperar os dados aqui)
    03-31 09:32:13.951 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoActivity onStart
    03-31 09:32:14.373 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoActivity AsyncCallBack
    03-31 09:32:14.412 25105-25105/com.amend.cockpit D/LifeCicle: PeriodoActivity list putExtras - (meu ArrayList é populado somente aqui)
    
        
    asked by anonymous 31.03.2016 / 16:30

    0 answers