Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid -- Why my app uses about 40MB Cached background process?
    primarykey
    data
    text
    <p>I'm starting a new app with minSdkVersion="14" and targetSdkVersion="17". It contains a viewpager with 6 pages. There is 3 webviews and 3 others views. </p> <p>When i push my app to background by clicking on back or home button, it uses about 40MB in "cached background process" and i don't understand why.</p> <p>This is an example of one of my webview :</p> <pre><code>import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.RelativeLayout; public class Presentation extends Fragment { boolean isOption = false; RelativeLayout main = null; WebView web_main = null; public Presentation () { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); main = (RelativeLayout) inflater.inflate(R.layout.webview, container, false); return main; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); web_main = new WebView(getActivity().getApplicationContext()); web_main.setWebViewClient(new WebViewClient()); web_main.getSettings().setAppCacheEnabled(false); web_main.loadUrl("file:///android_asset/main.html"); main.removeAllViews(); main.addView(web_main); } @Override public void onDestroy() { super.onDestroy(); Log.i(getClass().getName(), "[OnDestroy]"); main.removeAllViews(); web_main.destroy(); main = null; web_main = null; System.gc(); } } </code></pre> <p>I followed several tutorials and answers but there are no effect on cached background process This is my main activity : </p> <pre><code>public class AppTest extends FragmentActivity { /** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which * will keep every loaded fragment in memory. If this becomes too memory * intensive, it may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */ SectionsPagerAdapter mSectionsPagerAdapter; /** * The {@link ViewPager} that will host the section contents. */ ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_content); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter( getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); } @Override protected void onStop() { super.onStop(); System.gc(); Log.i(getClass().getName(), "[OnStop]"); android.os.Debug.stopMethodTracing(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main_content, menu); return true; } @Override protected void onDestroy() { super.onDestroy(); mViewPager.removeAllViews(); Log.i(getClass().getName(), "[OnDestroy]"); } /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ public class SectionsPagerAdapter extends FragmentStatePagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a DummySectionFragment (defined as a static inner class // below) with the page number as its lone argument. Fragment fragment = null; switch (position) { case 0: fragment = new Presentation(); break; /* case 1: fragment = new Edition(); break; case 2: fragment = new Programme(); break; case 3: fragment = new Twitter(); break; case 4: fragment = new Partenaire(); break; case 5: fragment = new Information(); break;*/ default: fragment = new Presentation(); break; } return fragment; } @Override public int getCount() { // Show 6 total pages. return 6; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return "Presentation"; case 1: return "Edition"; case 2: return "Program"; case 3: return "Tweets"; case 4: return "Partners"; case 5: return "Information"; } return null; } } } </code></pre> <p>Can anyone see what is wrong ? </p> <p><strong>EDIT</strong> I tried to put webview in layout but it's still the same In fact, i want to know what is put in cache when app is in background state ? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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