I would like to know the difference between use a Shared Reference / Editor and a static variable on a specific class.
To more explanation : I first use the Shared Reference in my project to share several variables between Services and Activity. But I'm starting on the Java and Android programmation and I have seen someone use a static variable in a public class.
But when do we need to use Static variable or Shared reference ?
Thanks.
CodePudding user response:
If you stored a value in a static variable and kill the application, 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.
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.