Nikhil PV
Nikhil PV

Reputation: 1012

When to use static variable and sharedpreference in android

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

Answers (3)

Atahar Hossain
Atahar Hossain

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

Ayush Jain
Ayush Jain

Reputation: 144

Shared Preferences is used to store and retrieved values.

There are plenty of link available :

1.Shared Preferences

2.Shared Preferences

Upvotes: 1

user3427729
user3427729

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

Related Questions