In Ionic4 Data storage and local storage is not working after the project is build as apk and installed in the phone

For reference:In Ionic 4 while i login as user i store a token in local storage and Data storage and using that token for several process like session handling and adding products. I check those process in browser it’s actually works but when build app as apk using ionic cordova build android… local storage and data storage is not working on the build apk.

I don’t know what you mean by “Data storage”. Phrases like “not working” aren’t very useful to people trying to diagnose problems. What is much more productive is if you can say “here is this code; I expect it to do X, but I see Y instead”. There is no decent reason to be using localStorage in an Ionic app; Ionic Storage is a better choice. Storage in general should only be used to communicate across app runs: store things that you will need the next time the user opens the app. If you’re using storage to communicate within an app run, I would suggest shifting to a mutually injected provider instead, otherwise you will be incurring performance penalties and fighting race conditions needlessly.

Finally, any time you interact with a native part of an Ionic app, you must make certain that it is ready to be interacted with. Whether you are doing that properly will be clear when you post code.

problem is with storage when I’m used that storage in browser it’s works but after a build as (apk) it doesn’t work jn mobile

I’m not seeing anything in this post that addresses anything I said, and “doesn’t work” isn’t any more useful than “not working”. I give up.


this is my coding… give some answers

I had a similar problem. My solution is like that (in app.module):

  name: '_myDb',
  driverOrder: ['localstorage']

Note: Duplicated thread. Duplicated answer. :slight_smile:

As I said upthread, it doesn’t make much sense to use localStorage. You have no guarantee how long it will persist.

Okay that’s fine…here I’m using Ionic data storage only but doesn’t works