以编程方式在Android上明确的PhoneGap /科尔多瓦应用程序的高速缓存来模拟一个新的安装? [英] Programmatically clear PhoneGap/Cordova app's cache on Android to simulate a fresh install?
问题描述
这是关系到我的previous的<问题href="http://stackoverflow.com/questions/11142069/how-can-i-clear-my-apps-localstorage-on-my-android-emulator-each-time-i-install">How我可以清楚我的应用程序的localStorage的在我的Android模拟器我安装它每一次?。
This is related to my previous question of 'How can I clear my app's localStorage on my Android emulator each time I install it?'.
这也建立在我如何清除Android应用程序缓存?和如何编程明确的应用程序数据?
无上述问题给出一个简单的答案是适用到Android的PhoneGap /科尔多瓦应用。 <一href="http://www.hrupin.com/2011/11/how-to-clear-user-data-in-your-android-application-programmatically"相对=nofollow>本博客文章通过伊戈尔Hrupin 涵盖的<强的背景情况>的本机的 Android的应用程序,所以这个问题扩展了覆盖科尔多瓦。
None of the above questions give a straightforward answer that is applicable to Android PhoneGap/Cordova applications. This blog post by Igor Hrupin covers the situation in the context of a native Android app, so this question extends that to cover Cordova.
我会后回答自己,但我是一个总的Java小白,所以请编辑来改善。
I will post an answer myself, but I am a total Java noob, so please edit to improve.
推荐答案
我是不是能够给力的Android重新加载新的版本:
I wasn't able to force android to reload new versions of:
super.loadUrl("file:///android_asset/www/index.html");
调用之间,所以我先借这已经足够好了,除了我的应用程序编写所有的数据已被删除,以及您的code。
between calls, so I first borrowed your code which worked well enough except that all data that my application was writing was deleted as well.
一个快速和简单的解决方法就是改变上述文件的URL:
A quick and simple fix is to change the URL of the file above:
super.loadUrl("file:///android_asset/www/index.html?1");
和改变落后多少?每个负载。最后我说:
And change the number behind the ? with each load. Eventually I added:
import java.util.Random;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
Random generator = new Random();
int r = generator.nextInt();
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html?" + r);
}
}
现在我每次重建应用程序,它实际上刷新的HTML文件的缓存版本。
Now each time I rebuild the app it actually refreshes the cached version of the html file.
我会非常想知道如何强制使用loadURL到刷新从应用程序本身,或迫使它重新加载。
I'd very much like to know how to force loadUrl into a refresh from within the app itself, or to force it on reload.
这篇关于以编程方式在Android上明确的PhoneGap /科尔多瓦应用程序的高速缓存来模拟一个新的安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!