1. Are you ready for the Galaxy S20? Here is everything we know so far!

Button to Clear just my apps cache

Discussion in 'Android Development' started by suran37, Dec 19, 2009.

  1. suran37

    suran37 Newbie
    Thread Starter

    I have an app that loads up a lot of images and can become a hog on the memory I suppose. So I am trying to make it so the user can click a button to clear the cache of the app.

    I have no idea how to do this but so far i have the button :p
    Code (Text):
    2. public class Clear extends Activity {
    3.     protected void onCreate(Bundle icicle) {
    4.         super.onCreate(icicle);
    5.         setContentView(R.layout.clear);
    7.         final Button trimCache = (Button) findViewById(R.id.trimCache);
    8.         trimCache.setOnClickListener(new View.OnClickListener() {
    9.             public void onClick(View v) {
    10.                 //clear the cache here
    11.             }
    12.         });
    13.     }
    14. }
    How would I go about making it clear only my apps cache?
    Also as a little bonus can i make it so it sends like a back command so that it returns to the main part of the app since this "Clear" page is accessed via a menu?

    1. Download the Forums for Android™ app!



Share This Page