Does using SharedPreferences drain resources? I have created class that uses SharedPreferences to store and retrieve application settings. Is it good idea to access SharedPreferences each time I need parameters? Will it drain system resources? 

class MqttSettings
{

    public static final String ADDRRESS ="address";
    public static final String PORT ="port";
    public static final String USERNAME ="username";
    public static final String PASSWORD ="password";
    public static final String CLIENTID ="clientid";

    public  SharedPreferences preferences;

    public  void setAddress(String value) {
        preferences.edit().putString(ADDRRESS, value ).commit();
    }
    public  void setPort(int value) {
        preferences.edit().putInt(PORT, value ).commit();
    }
    public  void setUsername(String value) {
        preferences.edit().putString(USERNAME, value ).commit();
    }
    public  void setPassword(String value) {
        preferences.edit().putString(PASSWORD, value ).commit();
    }

    public  void setClientId(String value) {
        preferences.edit().putString(CLIENTID, value ).commit();
    }

    public  String getAddress() {
        return preferences.getString(ADDRRESS,"192.168.1.8");
    }
    public  int getPort() {
        return preferences.getInt(PORT,8883);
    }
    public  String getUsername() {
        Log.d(Utils.LOGTAG,"getting username");
        String r = null;
        try {
            r= preferences.getString(USERNAME,"");
            Log.d(Utils.LOGTAG,"getting username preferences");
        } catch (Exception e) {
            Log.d(Utils.LOGTAG,"got exception "+e.getMessage());
            e.printStackTrace();
        }
        Log.d(Utils.LOGTAG,"getting username return");
        return r;
    }
    public  String getPassword() {
        Log.d(Utils.LOGTAG,"getting password");
        return preferences.getString(PASSWORD,"");
    }
    public  String getClientId() {
        return preferences.getString(CLIENTID,"");
    }

    public  String getUri()
    {
        String  uri ="tcp://";
        uri=uri+getAddress()+":"+getPort();
        Log.d(Utils.LOGTAG,uri);
        return uri;

    }

    public MqttSettings(SharedPreferences preferences)
    {
        this.preferences = preferences;
    }


}
Accessing SharedPreferences takes some definite amount of time because they are written and read from an actual file. So if you call this code too often from your mainThread, you will end up with ApplicationNotResponding errors and a bad user experience. The point is to call this on a background Thread (java) or coroutine(kotlin). The same goes for accessing the network, reading and writing to the database, long calculations etc 

https://developer.android.com/training/articles/perf-anr