Search code examples
androidandroid-fragmentssharedpreferencesbundle

Android sharedpreferences in each fragment or bundle from main activity?


I save some data like the user id (to make requests to apirest) using sharedpreferences, next I have an activity with 3 fragments which will use this id. Should I get the data (id) getting sharedpreference in each fragment? or should I getSharedPreferences in the main activity and pass the id using bundle??

My question: which option is faster and consumes less resources?and why?


Solution

  • Make a singleton class for SharedPreferences