When to use static variable and sharedpreference in android. Which is the best to use. Can anyone explain with example. Thanks in advance.
3 Answers
If you stored a value in a static variable and kill the application from recent(pressing Home button and clean all the running apps) then your value kept in static variable will be lost. But if you saved it in shared preference then you can read the saved value whether the application is killed from recent or not.
Comments
Shared Preferences is used to store and retrieved values.
There are plenty of link available :
1 Comment
Ayush Jain
Static Variable makes your program memory efficient.
Which is the best to usefeels like the question will have a lot of opinions. You may want to consider phrasing that part differently. You also may want to see if anyone has written any examples in the new Documenation beta.