jmarshall-com opened a new issue #1340:
URL: https://github.com/apache/cordova-android/issues/1340


   # 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 # .
   
   
   ### 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
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to