Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to destroy old fragments in FragmentStatePagerAdapter
    primarykey
    data
    text
    <p>I want to implement this: <img src="https://i.stack.imgur.com/jKOsg.png" alt="enter image description here"><br> I use a ViewPager with a FragmentStatePagerAdapter.<br> I started with the example from this page:<br> <a href="http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html" rel="noreferrer">http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html</a></p> <p>This is my ViewPager adapter: </p> <pre><code> public static class MyAdapter extends FragmentStatePagerAdapter { public MyAdapter(FragmentManager fm) { super(fm); } @Override public int getCount() { return NUM_ITEMS; } @Override public Fragment getItem(int position) { return ArrayListFragment.newInstance(position); } @Override public void destroyItem(ViewGroup container, int position, Object object) { super.destroyItem(container, position, object); } } </code></pre> <p>Every page of my ViewPager contains a ListView with some data. At the moment when I switch to a new page in ViewPager it will increase the RAM memory very quickly.<br> How should I remove the old fragments ?<br> I also used this but it does nothing: </p> <pre><code>public void destroyItem(ViewGroup container, int position, Object object) { FragmentManager manager = ((Fragment) object).getFragmentManager(); FragmentTransaction trans = manager.beginTransaction(); trans.remove((Fragment) object); trans.commit(); super.destroyItem(container, position, object); } </code></pre> <p>There is also a 1-2 seconds delay after I switch quickly to a new page or old page. Is there any technique to remove that delay. If I switch to a new page and wait for 2 second then on next switch there is no more delay.</p> <p>Tested on Nexus 7.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload