Reputation: 1012
When to use static variable and sharedpreference in android. Which is the best to use. Can anyone explain with example. Thanks in advance.
Upvotes: 2
Views: 1195
Reputation: 336
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.
Upvotes: 2
Reputation: 144
Shared Preferences is used to store and retrieved values.
There are plenty of link available :
Upvotes: 1
Reputation:
You can use static when there is not huge amount of data in the application. sharedpreference can be used if the data is more also and can be stored and retrieved as and when it is required.
Upvotes: 2