cordova-android icon indicating copy to clipboard operation
cordova-android copied to clipboard

After upgrading everything, in low memory, localStorage in onpause/onresume doesn't seem to work

Open jmarshall-com opened this issue 4 years ago • 0 comments

Bug Report

Problem

In low memory, and on physical device only: In my pause event handler, I do localStorage.setItem(...) . Then in my resume and deviceready event handlers, I do localStorage.getItem(...), but the retrieved value is always null. When using the emulator, it works as expected.

What is expected to happen?

localStorage.getItem() in resume or deviceready should get back the value that was set in localStorage.setItem(...) .

What does actually happen?

localStorage.getItem() in those handlers just returns null.

Information

This only happens on a physical device (I'm using a Pixel 2 XL). All is OK in the emulator.

An alert() in the pause handler (briefly) shows that the value is correctly set with localStorage.setItem() .

This could be related to bug #1319 .

Command or Code

HTML file index.html is:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content="default-src *">
        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="format-detection" content="telephone=no">
        <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index2.js"></script>
    </head>

    <body>
    </body>
</html>

JavaScript file index2.js is:

"use strict" ;

var app = {
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    onDeviceReady: async function() {
        alert('ondeviceready') ;
        document.addEventListener('pause', on_pause, false) ;
        document.addEventListener('resume', on_resume, false) ;

        let saved_state= localStorage.getItem('saved_state') ;
        alert('in ondeviceready, saved_state='+saved_state) ;    // is always null here when on physical device
        localStorage.removeItem('saved_state') ;
    },
};

app.initialize();


function on_pause() {
    localStorage.setItem('saved_state', 'test') ;
    alert('end of onpause, saved_state=['+localStorage.getItem('saved_state')+']') ;
}

function on_resume(event) {
    // this never runs-- apparently resume event isn't fired
    alert('in onresume, saved_state=['+localStorage.getItem('saved_state')+']') ;
}

Environment, Platform, Device

Using Linux for my dev machine, and testing on a physical Pixel 2 XL running Android 11.

Version information

Cordova CLI 10.0.0 Pixel 2 XL running Android 11

output of cordova plugin ls:

cordova-clipboard 1.3.0 "Clipboard"
cordova-plugin-add-swift-support 2.0.2 "AddSwiftSupport"
cordova-plugin-android-permissions 1.1.2 "Permissions"
cordova-plugin-androidx-adapter 1.1.3 "cordova-plugin-androidx-adapter"
cordova-plugin-autostart 2.3.0 "Autostart"
cordova-plugin-background-mode 0.7.3 "BackgroundMode"
cordova-plugin-camera 6.0.0 "Camera"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-fetch 0.1.0 "Cordova Fetch"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-photo-library 2.2.1 "Photo Library"
cordova-plugin-save-to-camera-roll 1.0.2 "Save to camera roll"
cordova-sqlcipher-adapter 0.4.0 "Cordova sqlcipher adapter"
cordova-sqlite-storage 6.0.0 "Cordova SQLite storage plugin - cordova-sqlite-storage plugin version"

output of cordova platform ls:

6.0.0
Installed platforms:
  android 10.1.0
  browser
  ios 6.1.1
Available platforms: 
  browser ^6.0.0
  electron ^1.0.0

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

jmarshall-com avatar Sep 08 '21 00:09 jmarshall-com