0

enter image description here

My application has a section like that one. Each section parse json data from different url and show it on a custom listview. Now, when I navigate section 2 to section 3. Each fragments show data but when navigate 2 to 3 to 4 and then comeback to 2. Section 2 parse data again from web.

Now, is there any to saving data(not in the database). So, that If I navigate 2 to 3 to 4 and then comeback to 2 it will not parse data again.

Adnan
  • 8,468
  • 9
  • 29
  • 45

2 Answers2

0
Simply fallow undermentioned and let me know if you have any issues regarding same. I faced this problem:-

(1) Define a boolean value with value "false".
(2) Now when you are done with fetching data then simply change it to true.
(3) Now when you render back to any screen that have downloaded data simply check that value to be true/false. you will check same on OnCreateView. If value is false then let AsyncTask be run else wise don't allow AsyncTask to run.

For ex: 

<


if(vivek != true){
        new GoAsyncTask().execute();
        }else{

            gaa = new GoArrayAdapter(getActivity(), m_ArrayList);
            lv = (ListView) rootView.findViewById(R.id.go_list);
            lv.setVisibility(View.VISIBLE); 
            lv.setAdapter(gaa);

            lv.setOnItemClickListener(new OnItemClickListener() {

                @SuppressWarnings("static-access")
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
                    dh.open();
                    dh.updateSeenStatus(m_ArrayList.get(arg2).postid, 1);
                    dh.close();
                    m_ArrayList.get(arg2).isSeen = true;
                    GoDetail fragment = new GoDetail();
                    Bundle bundle = new Bundle();

                    bundle.putString("title", m_ArrayList.get(arg2).title);
                    bundle.putString("excert", m_ArrayList.get(arg2).excert);
                    bundle.putString("description", m_ArrayList.get(arg2).description);
                    bundle.putString("thumsrc", m_ArrayList.get(arg2).thumsrc);
                    bundle.putString("header_title", "Go");
                    //bundle.putInt("postid", m_ArrayList.get(arg2).postid);

                    fragment.setArguments(bundle);
                    ((BaseContainerFragment)getParentFragment()).replaceFragment(fragment, true);
                }
            });

        }
>
AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
0

The following combination is a sure-winner for me all the time for these types of layout and behavior:

Tabs + ViewPager + Fragments + Loader(specifically AsyncTaskLoader)

Tabs + ViewPager are presenting the layout in the way you need to have. You may be aware of developer article that shows how to build this type of layout. ViewPager + Fragments, here's another dev article that shows how to set it up.

Loaders biggest advantage over AsyncTask is that it knows to keep the data when you recreate the activity or fragment so you don't need to ask it again. The data loading is decoupled from UI life-cycle. The developer article describing the loaders is the best place to get you started. You could use the AsyncTaskLoader since it is similar to AsyncTask at some points (actually AsyncTaskLoader uses an AsyncTask)

gunar
  • 14,660
  • 7
  • 56
  • 87