How to auto-save a form on Android - Best practices

730 views Asked by At

Sample app

I am trying to introduce auto-save functionality on one of my Android applications. The idea is that as the user inputs first name, last name and after a fixed interval I would like to save that information to the server before the user hits Next button. The final goal is to have something similar to the draft option in the Gmail app where your email information is automatically saved. So, if there is a timer that runs every 10 seconds, I will pass the information on the screen to the ViewModel and let it deal with the logic of saving the data to the server.

A couple of options I have explored are.

  1. Execute recurring code with a specified interval using Handler.
  2. PeriodicWorkRequest -- however this option has a minimum interval of 15 minutes which is a little too much for my use case.
  3. AlarmManager -- This option runs even if your application is not currently running, In my opinion, this option can be an overkill.

I wanted to know if there are best practices/blogs around this and if anyone I on the wrong path or potential red flags with this approach.

1

There are 1 answers

0
Jalalkun On

you can make countdown for 10 second, when countdown is down save the data and call the countdown again. when your activity is destroyed, so stop the countdown