即使应用程序被删除,Cordova应用程序中的Web存储也会被转移

hug*_*gie 3 android local-storage cordova

在Cordova Android应用程序中,当我使用Web存储(window.localStorage)时,我注意到有时当我卸载应用程序(甚至通过adb uninstall)并再次重建应用程序时,window.localStorage的东西似乎会被遗留下来.

这不只是在一台Android设备上,我在不同设备上多次注意到它.

这甚至可能还是只是页面被缓存了?

编辑:

我创建了一个示例项目.并使用Cordova 8和Android平台7.0.0.我配置得对吗?

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloWorld</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:allowBackup="false" />
            <application android:fullBackupContent="false" />
        </edit-config>
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="android" spec="^7.0.0" />
</widget>
Run Code Online (Sandbox Code Playgroud)

jce*_*ile 8

Android 6+会自动备份数据,并在您再次安装应用程序时进行恢复.

您可以通过将其添加到config.xml来禁用它

<edit-config file="AndroidManifest.xml"
             target="/manifest/application"
             mode="merge">
    <application android:allowBackup="false"/>
    <application android:fullBackupContent="false"/>
</edit-config>
Run Code Online (Sandbox Code Playgroud)

这使得应用程序构建失败,您必须添加xmlns:android="http://schemas.android.com/apk/res/android"到config.xml小部件以使其构建.

  • 啊,我只是检查AndroidManifest.xml是否正在被编辑,但是没有尝试运行应用程序,那就是出现错误的时候.要修复它,请从`<widget id ="com.example.hello"version ="1.0.0"xmlns ="http://www.w3.org/ns/widgets"xmlns:cdv ="更改config.xml http://cordova.apache.org/ns/1.0">`到`<widget id ="com.example.hello"version ="1.0.0"xmlns ="http://www.w3.org/ns/widgets"xmlns:android ="http://schemas.android.com/apk/res/android"xmlns:cdv ="http://cordova.apache.org/ns/1.0">` (2认同)