android - Should I put getDefaultSharedPreferences in application class -


as far know getdefaultsharedpreferences loading preference file memory. in app have many classes pass context , use getdefaultsharedpreferences. during execution these classes load many times, result getdefaultsharedpreferences called allot. question is: should load preferences 1 time in application class , access preferences there in classes? doable? increase speed of app? did this?

something this:

private static myapplication singleton;  public static myapplication getinstance() {     return singleton; }  @override public void oncreate() {     super.oncreate();     mypreferences = preferencemanager.getdefaultsharedpreferences(this); }  public sharedpreferences getpreferences(){     return mypreferences; } 

sharedpreferences caches after first load, disk access load data take time 1 time.once in memory, after first reference. first time retrieve specific sharedpreferences (e.g., preferencemanager.getdefaultsharedpreferences()), data loaded disk, , kept around.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -