I am writing a little note pad app, where users can enter text notes, which are saved to the file system.
I am wondering what is the right balance between persistence and battery life (in terms of frequent I/O)
I want to ensure that a user will experience minimal loss in the event of a power outage.
That requirement suggests that a flush to the file system should be performed after every few characters are typed (using some throttling)
On the other hand, that strategy would use too much battery.
So what should be the right blend of durability and performance?
Infrequent File I/O won’t do much to hurt battery life. Even at once every 10 seconds, battery drain won’t be that big if you do it correctly (ie. disable the timer [or whatever] when your app goes off screen, check that you really need to save when the timer fires, etc.).
That being said, File I/O after every keystroke is excessive. Here are some ideas:
Here’s a link to a very simplistic Battery Changed intent filter:
https://web.archive.org/web/20200721185308/http://www.tutorialforandroid.com/2009/01/getting-battery-information-on-android.html