android - 强制重新启动完整的应用程序以刷新 Cordova 中的包

标签 android ios cordova meteor cordova-plugins

我希望从应用程序本身完全重启应用程序(真正重启应用程序(满载)而不仅仅是重新呈现索引)。

这需要发生,因为一些包也需要重新初始化,这只能在完全重新启动应用程序时完成。

我试过这个包https://www.npmjs.com/package/cordova-plugin-exit这似乎不起作用。

navigator.app.exitapp() 也不是我要找的东西,或者这是否完全符合我的要求?

创建一个 cordova 包装器插件的最佳解决方案是否以不同的方式为 android 和 IOS 执行此操作?

最佳答案

您可以在 Android 上使用 restart() 执行此操作cordova-diagnostic-plugin的方法:

// Warm restart
cordova.plugins.diagnostic.restart(null, false);

// Cold restart
cordova.plugins.diagnostic.restart(null, true);

By default, a "warm" restart will be performed in which the main Cordova activity is immediately restarted, causing the Webview instance to be recreated.

However, if the cold parameter is set to true, then the application will be "cold" restarted, meaning a system exit will be performed, causing the entire application to be restarted. This is useful if you want to fully reset the native application state but will cause the application to briefly disappear and re-appear.

Note: There is no successCallback() since if the operation is successful, the application will restart immediately before any success callback can be applied.

无法在 iOS 上以编程方式重启应用程序;至少这样做可能会使您的应用程序被 App Store 拒绝。

关于android - 强制重新启动完整的应用程序以刷新 Cordova 中的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52258488/

相关文章:

ios - 为 Phonegap 3.1 (iOS) 安装插件时出错

html - 如何将 cordova apk 转换为 html 源而不是 java

java - Android:使用 Twitter API 1.1 oAuth

java - 显示软键盘时无法让 ScrollView 滚动

android - 用于构建 Android 应用程序的 Gwt

ios - Xcode 7 GM,Swift 2.0 涉及 range 和 advancedBY 的变化

ios - 播放用 AVFoundation 录制的视频

android - 在 Android 中从 shell 杀死进程

ios - 如何使用雅虎!在 iOS 应用程序中联系 api?

javascript - 如何在phonegap网站提交插件?