user2465819
user2465819

Reputation: 37

how to save my app preference and retrieve them after re-install or change of device

I'm new to app dev...

I read somewhere in the doc: "...In most cases you want to use SharedPreferences as it is automatically backed up and migrated to new devices..."

On first install my app saves a few settings with SharedPreferences. It works great but if I uninstall the app or install it on another device the preference settings are lost.

How can I have these settings saved online within google somehow to be able to retrieve them if the user changes his phone or similar...

Could someone point me in the right direction ?

Upvotes: 2

Views: 230

Answers (2)

sandhya sasane
sandhya sasane

Reputation: 1352

I read somewhere in the doc: "...In most cases you want to use SharedPreferences as it is automatically backed up and migrated to new devices..."

  1. Your words "backed up and migrated to new devices" is nowhere written nor its true.
  2. We use SharedPreferences in order to minimise the database operations, its like keeping variables handy.

On first install my app saves a few settings with SharedPreferences. It works great but if I uninstall the app or install it on another device the preference settings are lost.

  1. If you wants to store or remember the device dependent settings, use device id / imei_id and store it on your web server mysql database
  2. Even if user uninstalls app from the device and installs again anytime in future, make a call with async task to server by sending deviceid / imei_id and fetch its settings from mysql database and show it.

How can I have these settings saved online within google somehow to be able to retrieve them if the user changes his phone or similar...

  1. If user changes device, you can do nothing.
  2. One way is, keep public device_id levels keys on server.
  3. If user changes device and uses that key, then show him a response, this key is assigned to another device, but if you are the same, wait for our support
  4. Call him, confirm he is the same old user with new device and delete his old entry from mysql and assign old key to the new device entry
  5. Or use OTP SMS system to identify already existing customers with unique phone numbers
  6. If OTP authentication code is correct then fetch settings for that user from the server, delete old mysql entry, modify new entry with old key and mobile number

This should be the your direction

Edit : 2 ##

I was hoping an easier solution exist but....

There is no short cuts for developers till the date, and it will be never.

Why, no short cuts / easy ways ?

Any device ( mobile, desktop / laptop / any AI device ) which is operated by a system software, is able to perform the tasks as per it is structured.

Ex : android is java based, obviously you can Make javascript based apps, but it is the extensions to the existing system, Android still has the base of Java virtual machine. ( Dalvic / Malvic like )

  1. So, it is always better to use native java
  2. Yes, Kotlin is best option now a days and better than hybrid approach
  3. Every way has its own advantages, disadvantages
  4. If you are developer, should go with native approach
  5. Now your java code never knows, which version it is running on, so you have to, check android versions programming wise, and decide the flow for above Marshmallow & below marshmallow too, and it is explicitly done by developer by coding.
  6. Ex, once user registers, he never shown please register again screen, it is not the magic, nor google, nor, java, nor android does anything, developer has decided, planned, architectured, designed, coded, tested that.
  7. Even developers needs to take care of exceptions, you need to handle it in order to save your app from crashing.
  8. In short developer is god, who creates his own universe, and everything is pre-planned and verified thats it.

Upvotes: 1

p.mathew13
p.mathew13

Reputation: 921

You should use allowBackup = "true" in your manifest file. More details can be found here: AutoBackup

Upvotes: 0

Related Questions