PreferencesModule sample
pritam2102 opened this issue · 3 comments
pritam2102 commented
Hello.
I have read your mvvm architecure i.e. very good. can you please provide how to use sharedPreference in your sample
@Module
class PreferencesModule {
/**
* Provides Preferences object with MODE_PRIVATE
*/
@Provides
@Singleton
fun provideSharedPreference(app: Application):
SharedPreferences = app.getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE)
}
pritam2102 commented
after R and D sample code found and implemented
Rohitsachdeva commented
please share an example of using this in activity or fragment
WaheedNazir commented
You can inject like this in activity / fragment
@Inject
lateinit var sharedPreferences: SharedPreferences
To save
sharedPreferences.edit().putString("YOUR_KEY","123456").apply()
To retrieve
sharedPreferences.getString("YOUR_KEY","defaultValue")