- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
任何人都可以向我解释 keepRunning 在 Android 的 config.xml 中是如何工作的。
我的意思是,我不想知道如何编写指令,但它是如何工作的,它如何影响 Android 应用程序的执行?它会在后台创建服务吗?
如果有人能找到我们可以看到它是如何工作的来源,那就太好了
谢谢。
编辑: 我尝试分析生成的代码,分析 Android 设置中的 RAM、服务和进程。而我的结论是……什么都不做。如果您尝试制作一个使用 GPS 跟踪用户的应用程序,请不要使用 Cordova。要正确跟踪用户,您需要使用 START_STICKY 选项创建服务。所以,它是在 native 代码中。你失去了对 CrossPlatform 的兴趣,因为你必须为所有平台重新编码服务,在我看来,Native Service 和 Cordova App 之间的通信并不容易。
总而言之,如果你使用 Cordova,你必须知道你不能使用所有原生的力量,你必须做出选择:- 简单的开发(主观)和跨平台(真的跨平台?)和- native 开发具有强大的功能且没有兼容性问题,但您必须为一个平台制作一个应用
最佳答案
我不是 JS/Cordova 开发人员,我是 Android 开发人员。有一次我在 Cordova 插件上工作,遇到了一些问题,并对这个主题做了一些调查。
keepRunning 标志的一般用途是指示当应用程序暂停(进入后台)时是否应停止 JS 计时器。回答您的问题:不,它不会创建任何新的服务。现有的设计在这方面已经很简单了。
keepRunning 标志在 CordovaActivity.java 中定义如下:
// Keep app running when pause is received. (default = true)
// If true, then the JavaScript and native code continue to run in the background
// when another application (activity) is started.
protected boolean keepRunning = true;
它的主要目的是在 Cordova 应用暂停时禁用JS 计时器,在CordovaWebView.java :
public void handlePause(boolean keepRunning)
{
LOG.d(TAG, "Handle the pause");
// Send pause event to JavaScript
this.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};");
// Forward to plugins
if (this.pluginManager != null) {
this.pluginManager.onPause(keepRunning);
}
// If app doesn't want to run in background
if (!keepRunning) {
// Pause JavaScript timers (including setInterval)
this.pauseTimers();
}
paused = true;
}
请注意,插件也会通过 PluginManager 收到通知,因此理论上它们可以处理应用程序暂停事件,以停止(或不停止)它们在后台的 Activity ,具体取决于 keepRunning旗帜。
在我的例子中,当 keepRunning 为 true 时,我遇到了问题/错误,但 JS 计时器无论如何都停止了。这是因为在 CordovaActivity.java 中有与该标志相关的附加功能。 :
/**
* Launch an activity for which you would like a result when it finished. When this activity exits,
* your onActivityResult() method will be called.
*
* @param command The command object
* @param intent The intent to start
* @param requestCode The request code that is passed to callback to identify the activity
*/
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
this.activityResultCallback = command;
this.activityResultKeepRunning = this.keepRunning;
// If multitasking turned on, then disable it for activities that return results
if (command != null) {
this.keepRunning = false;
}
// Start activity
super.startActivityForResult(intent, requestCode);
}
当 Cordova 应用程序启动另一个 Android Activity 时,主要的 Cordova Activity (带有 WebView 的屏幕)进入后台并因此暂停。在我的例子中,它是通过谷歌地图插件制作的,该插件在 Cordova 应用程序上启动 GM 屏幕。
上面的代码关闭了 keepRunning 标志,这意味着当调用的 Activity 出现时(在 CordovaActivity.onPause 方法中)JS 计时器无论如何都会停止,无论 keepRunning 是真还是假!
它看起来像是为了某些不明确(且未记录)的目的而实现的一种技巧,我不知道它的上下文。在我的例子中,它导致了一个错误,我只是删除了 startActivityForResult 中的 keepRunning 处理,重新编译了 Cordova,它工作正常。
添加:关于使用 GPS 服务 - 你说得很对,我同意。作为具有相关 (GPS) 经验的 Android 开发人员,我可以说正确的方法(并且可能是唯一可接受的方法)是为此使用服务。据我所知,Cordova 没有为它提供任何功能,所以我认为它应该通过插件来制作。我的意思是您可以为 GPS 功能编写 native Android 代码(作为服务实现)并从 JS 代码访问它。我相信这是 Cordova 中针对此类情况的常见解决方案。
关于android - keepRunning PhoneGap/ Cordova ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21001439/
我使用plugman命令在cordova中创建了一个插件 它创建了所有必需的文件。然后我在插件中添加了android平台。 然后我尝试将它添加到 cordova 应用程序中。我成功添加了它,但是当我尝
我使用plugman命令在cordova中创建了一个插件 它创建了所有必需的文件。然后我在插件中添加了android平台。 然后我尝试将它添加到 cordova 应用程序中。我成功添加了它,但是当我尝
我正在尝试在较旧的 Atrix 上安装一个应用程序,在 S3 上运行良好。搜索论坛可能的问题是SDK版本较高(Atrix是4.0.4)。修复显然是在设置 API 级别。 但是当我运行 cordova
使用 cordova build在一个为期一年的项目中提出: :processDebugResources my_project/platforms/android/build/intermediat
我有一个可以创建文件的可运行应用程序。 我正在寻找一种工作后数小时从cordova应用程序中删除文件的方法。我似乎无法使其正常工作。 这是用于创建和删除文件的代码: function crea
有什么区别吗Cordova 构建 Android 和 Cordova 准备 Android 命令? Reference is added here 最佳答案 准备将您的 www Assets 和任何插
我检查了文档,但没有找到关于此命令的明确说明。 那么,有谁知道cordova prepare命令的作用是什么? 是否更新特定于平台的www文件夹? 如果是,它将复制根www的全部内容吗? 它会更新平台
我们正在开发正在使用Cordova(专用于Ionic)的移动应用程序,并且正在使用PhoneGap PushPlugin和Amazon SNS进行推送通知。反过来,这会撞到我们与Amazon SNS进
我正在使用Vue,Webpack和Cordova。 Videos 如果我在没有Cordova的情况下加载页面,并且在Firefox浏览器中,则可以使用Youtube视频上的全屏图
因此,我尝试在我的(正在运行的)Ionic应用程序中安装一个新插件,该文件名为https://ionicframework.com/docs/native/firebase-dynamic-links
我像这样安装了cordova: C:\Windows\system32>npm install -g cordova 我明白了: C:\Users\cyril\AppData\Roaming\npm\
我有一个 cordova 应用程序,我使用以下代码捕获了后退按钮: document.addEventListener("backbutton", function (e) { bac
如何在 Cordova 中的蓝牙设备和 Android/iOS 之间发送和接收一系列数据字节? 我的项目的详细信息: 我正在开发一个蓝牙传感器设备。设备以一系列字节的形式发送数据。它还对设备 API
我是 cordova 开发的新手。我使用 Onsen UI (1.2.1) 作为布局框架。ons-toolbar 上的标题有问题。 someTextHere 如果我在 ripple 上运行
我有一个启用了平台浏览器的 Cordova 应用程序。我想在 Chrome 中使用摄像头,但调用摄像头根本没有任何反馈。它在我的 Android 设备上就像一个魅力。 我通过这个命令启动:cordov
我对thid docs https://firebase.google.com/docs/android/setup#available_libraries中提到的根级和应用程序级的路径目录感到困惑
喜欢这些插件 https://github.com/ArchieGoodwin/SilentShot https://github.com/alongubkin/phonertc 他们没有 tarba
我有一个 Angular 2 应用程序,我正在将其构建到 cordova 中并部署到 Android/IOS。我没有使用 ionic,我见过许多使用 ionic 的解决方案,但我现在无法将整个项目转换
当我发出命令时,在带有 Cordova 的 Ionic 3 中: ionic cordova run android --emulate 它给出以下消息: BUILD FAILED in 3s
我无法在 ionic 5.2.4v 中安装软件包 cordova-res 并收到以下错误。 命令:cordova-res C:\hanu\cordova-res-master\cordova-res
我是一名优秀的程序员,十分优秀!