juil
juil

Reputation: 2488

Are there any downsides to editing SharedPreferences regularly?

The example code for SharedPreferences on developer.android.com shows the editor being called in the onStop() method.

Is this because editing SharedPreferences is resource intensive? Is it okay to edit SharedPreferences on a function called regularly in the program? Or should changes be kept to local variables and only be called onStop()?

Upvotes: 2

Views: 52

Answers (1)

Jin
Jin

Reputation: 6145

sharedprefs are backed by a local file in your /data/ directory, so yes saving data involves disk I/O which is not cheap. The performance impact might be negligible depending on what you are trying to do though because the saving is done on a background worker thread.

There isn't an answer to this question. You need to run experiments and measure performance across different devices and OSes to gauge what kind of impact this will have.

Upvotes: 1

Related Questions