Log in

I forgot my password

Poll

What size screen do you think is best for the next device?
12% 12% [ 6 ]
23% 23% [ 12 ]
21% 21% [ 11 ]
13% 13% [ 7 ]
31% 31% [ 16 ]

Total Votes : 52

Latest topics

» Rebuild gator driver to open mali option
Today at 3:06 pm by ilgwt

» Memory, final code and final video (in Spanish)
Today at 9:05 am by Alvaro

» ODROID-A4 IO Board
Today at 6:36 am by tuxfield

» odroid linux kernel config file "hkdk_rtm20_defconfig " missed
Yesterday at 10:09 am by odroid

» odroid-7 source code
Sun May 20, 2012 7:52 am by odroid

» Application source code for Embedded Android Platform based on ODROID-A4
Sun May 20, 2012 2:52 am by odroid

» What is ODROID-BaB project LSED?
Sat May 19, 2012 9:44 am by Alvaro

» CPU Module S5PV310 and K3PE7E700B
Fri May 18, 2012 6:01 am by odroid

» BF040-I50B_N09 Board to Board Connector
Thu May 17, 2012 4:45 am by efung

» CPU Module Schematics
Thu May 17, 2012 2:37 am by odroid

» A stupid question : How can I root the ODROID-A
Wed May 16, 2012 7:05 am by Bingley

» ODROID-PC Ubuntu 12.04 with HDMI
Tue May 15, 2012 12:33 pm by grikukan

» ODROID-A4 IO Board - Oscilloscope
Tue May 15, 2012 11:48 am by tuxfield

» OPEN RFID Tag
Tue May 15, 2012 7:51 am by Alvaro

» About the recovery tool for Odroid-pc
Tue May 15, 2012 6:37 am by odroid


    Clear cache of an application in android while Exit

    Share

    Alvaro
    Admin
    Admin

    Devices: ODROID, ODROID-T, ODROID-7, ODROID-A, ODROID-ADK, ODROID-BaB, ODROID-PC, ODROID-E7, ODROID-A4
    Posts: 929
    Join date: 2010-05-09
    Location: Madrid, Spain

    Clear cache of an application in android while Exit

    Post by Alvaro on Thu Apr 07, 2011 7:14 pm

    Hi,

    Sometimes we face different kind of problems with cache of an application in android like showing old data for a web page in a Web view and the same problems will arise for a URLConnection also.

    If you are working with a GPS based application, There it will generate big size of cache files. It is better to delete this cache. Here is the sample Activity for doing this job. It will identify the directory containing these cache files and delete them.

    Code:
    import java.io.File;

    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;

    public class HelloWorld extends Activity {

       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle *) {
          super.onCreate(*);
          setContentView(R.layout.main);
       }

       @Override
       protected void onStop(){
          super.onStop();
       }

       //Fires after the OnStop() state
       @Override
       protected void onDestroy() {
          super.onDestroy();
          try {
             trimCache(this);
          } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }
       }

       public static void trimCache(Context context) {
          try {
             File dir = context.getCacheDir();
             if (dir != null && dir.isDirectory()) {
                deleteDir(dir);
             }
          } catch (Exception e) {
             // TODO: handle exception
          }
       }

       public static boolean deleteDir(File dir) {
          if (dir != null && dir.isDirectory()) {
             String[] children = dir.list();
             for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                   return false;
                }
             }
          }

          // The directory is now empty so delete it
          return dir.delete();
       }
       
    }


    Thanks,

    Álvaro


    _________________
    Alvaro

      Current date/time is Tue May 22, 2012 6:16 pm