我有这个代码来自另一个问题.
public static voID deleteCache(Context context) { try { file dir = context.getCacheDir(); if (dir != null && dir.isDirectory()) { deleteDir(dir); } } catch (Exception e) {}}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; } } } return dir.delete();}
所以基本上我的POSActivity.java看起来像这样.
public class PocActivity extends DroIDGap {/** Called when the activity is first created. */@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); super.setIntegerProperty("splashscreen",R.drawable.is); super.setIntegerProperty("loadUrlTimeoutValue",60000); deleteCache(this); super.loadUrl("file:///androID_asset/www/index.HTML");}public static voID deleteCache(Context context) { try { file dir = context.getCacheDir(); if (dir != null && dir.isDirectory()) { deleteDir(dir); } } catch (Exception e) {}}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; } } } return dir.delete();}}解决方法 加载index.HTML后,在活动文件的oncreate()方法中添加以下代码:
if (super.appVIEw != null) { super.appVIEw.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);}总结
以上是内存溢出为你收集整理的在Phonegap android上清除用户数据或清除缓存全部内容,希望文章能够帮你解决在Phonegap android上清除用户数据或清除缓存所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)