缓存未清除

时间:2013-09-26 05:10:37

标签: android clear-cache

我有一些HTML页面用于设计和实现某些功能。当我启动应用程序时,我从资源文件夹加载一个HTML文件。在这个Activity中我有index.html页面。在这里,当我点击按钮时,它转到关于页面。如果关闭应用程序,打开它会显示关于页面。为什么它没有加载索引页面。

代码:

public class MainActivity extends DroidGap {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Runnable rn =new Runnable(){

            @Override
            public void run() {
                // TODO Auto-generated method stub

                OnDestroy();

            }

         };
        super.setIntegerProperty("splashscreen", R.drawable.splash); 
        super.loadUrl("file:///android_asset/www/index.html", 3000); 

}

public void OnResume(){
 super.loadUrl("file:///android_asset/www/index.html", 3000); 

}

    public void OnDestroy(){

        try {
            trimCache(this);
            Toast.makeText(this,"onDestroy " ,Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    public static void trimCache(Context context) {
        try {
           File dir = context.getCacheDir();
           Toast.makeText(context, "Delete", Toast.LENGTH_SHORT).show();


           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();
     }

使用Resume错误logcat:

09-26 13:07:11.360: D/CordovaLog(326): file:///android_asset/www/js/script.js: Line 60 : 415
09-26 13:07:11.360: I/Web Console(326): 415 at file:///android_asset/www/js/script.js:60
09-26 13:07:11.590: E/CordovaWebView(326): CordovaWebView: TIMEOUT ERROR!
09-26 13:07:11.610: D/Cordova(326): CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html
09-26 13:07:11.661: D/CordovaActivity(326): onMessage(onReceivedError,{"errorCode":-6,"url":"file:\/\/\/android_asset\/www\/index.html","description":"The connection to the server was unsuccessful."})
09-26 13:07:12.250: D/Cordova(326): onPageFinished(file:///android_asset/www/index.html)
09-26 13:07:12.250: D/CordovaActivity(326): onMessage(onPageFinished,file:///android_asset/www/index.html)
09-26 13:07:12.270: D/SoftKeyboardDetect(326): Ignore this event

如果我没有使用onResume方法,我得到了这个错误:

09-26 13:34:50.060: I/CordovaLog(824): Found start page location: index.html
09-26 13:34:50.071: I/CordovaLog(824): Changing log level to DEBUG(3)
09-26 13:34:50.090: D/CordovaActivity(824): Resuming the App
09-26 13:34:50.090: D/CordovaActivity(824): CB-3064: The errorUrl is null
09-26 13:34:50.160: D/CordovaLog(824): : Line 1 : exception firing resume event from native
09-26 13:34:50.171: I/Web Console(824): exception firing resume event from native at :1

0 个答案:

没有答案