jQuery Mobile以编程方式重新初始化/重新启动应用程序 [英] jQuery Mobile programmatically reinitialise/restart app
问题描述
我正在用phonegap和jquery mobile编写一个应用程序.
I am writing an app with phonegap and jquery mobile.
要处理未知错误,我需要完全重新启动我的应用程序,并将所有变量和动态内容重新初始化为与第一次运行等效.
For handling unknown errors I need to completely restart my app and reinitialise all variables and dynamic content back to being the equivalent of the first run.
最初,我只是使用$ .mobile.changePage($'#home'),因为它没有重新初始化任何动态内容或变量,所以它显然不起作用,所以我最终遇到了麻烦.
Originally I was just using $.mobile.changePage($'#home') which obviously doesn't work because it doesn't reinitialise any of the dynamic content or variables so I end up with double ups.
有没有可以在jquery mobile中调用的方法来完全重新启动应用程序并将所有设置都恢复为初始设置?
Is there a method I can call in jquery mobile to completely restart the app and set everything back to the initial settings?
推荐答案
要获得完整的解决方案,我认为您不走运.
For a full solution, I think you are out of luck.
iOS绝对不会*不允许以程序方式杀死应用程序,更不用说以程序方式启动应用程序了.
iOS definitely will *NOT allow the programatic killing of an app, let alone the programatic starting one.
Android确实允许杀死应用程序.虽然没有记录(我可以找到),但是您可以使用
Android does allow the killing of an app. Though undocumented (that I could find) you can use
navigator.app.exitApp();
navigator.app.exitApp();
杀死当前应用.
但是,您仍然无法以编程方式重新启动它.
However, you still cant re-start it programaticly.
我认为您最好的选择是编写代码来重置变量和本地存储/数据库(如果使用).然后通过document.location.href = 'index.html?var=xxx';
重新加载索引页,其中xxx =当前时间戳.将时间戳记放在末尾将确保它提取页面的非缓存版本.
I think your best bet will be to write the code to reset the variables and local storage/DB (if used). Then reload the index page via document.location.href = 'index.html?var=xxx';
where xxx = the current timestamp. Placing the timestamp at the end will ensure that it pulls a non-cached version of the page.
*在我关于Apple允许应有的应用程序终止功能的声明中,添加了 not .
* Added not to my statement about Apple allowing app killing as it should have been.
这篇关于jQuery Mobile以编程方式重新初始化/重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!