Restart my Phonegap app programmatically

烂漫一生 提交于 2019-12-18 01:29:15

问题


How can I programmatically restart my phonegap app? I exit the app easily through navigator.app.exitApp(), but I would like it to restart immediately.

The reason I need this, is I have to restart it after the user chooses his user language from a selectbox menu. The i18n immediately fires after the user updated his language choice, apart from 5 buttons on 1 page and a paragraph on another page. Those 5 items remain in the previous language (also the language select menu layout gets completely destroyed for some reason), but when I restart the application they're all in the correct language. There's either a very complicated problem with the i18n process, or I can backdoor solve it with the forced restart.

Ty, Nutty


回答1:


I use the following:

location.reload(); 

Works a treat for me.

Paul




回答2:


Try this

navigator.app.loadUrl("file:///android_asset/www/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});

Bakri




回答3:


This works for iOS and Android (at least with 2016 platform versions). It works also in SPA applications.

// keep startup url (in case your app is an SPA with html5 url routing)
var initialHref = window.location.href;

function restartApplication() {
  // Show splash screen (useful if your app takes time to load) 
  navigator.splashscreen.show();
  // Reload original app url (ie your index.html file)
  window.location = initialHref;
}


来源:https://stackoverflow.com/questions/15477887/restart-my-phonegap-app-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!