sharedpreferences – Android Studio, Lanzar una notificacion a dispositivos que tengan activado el canal de notificación

Tengo en mi proyecto en un Fragment varios canales de notificación creados con preferences, lo que necesito saber es como lanzar notificaciones a través de esos canales de notificación, pero solo para los dispositivos que tengan los canales activados, si no están activados que no mande nada pero cada vez que mande una notificación solo lo recivan dichos dispositivos. Agradecería una ayudita porque en esta parte estoy un poco bloqueado sobre como hacerlo

android – Change ImageView with Sharedpreferences

I'm having trouble saving button state Shared preferences, in case I try to change the image that is in ImageView from the other as soon as the button is pressed, that is to say:
Level 1 is ok, but level 2 needs $ 100 to unlock, in addition to the level 2 image is a padlockas soon as the user buys the lock disappears and he can access the level, as if it were a game phase.
In a way, I did it, but when I quit the app, everything was as before.
Thanks in advance!

java – Does using SharedPreferences consume resources?

I created a class that uses SharedPreferences to store and retrieve application settings. Is it a good idea to access SharedPreferences whenever i need settings? 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,"");
    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());
        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://";
        return uri;


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


java – SharedPreferences is indicated to save objects?

I have searched for several foreign sites but I have not found anything, including here.

I have a problem with the application which, whenever the user minimizes it and uses the phone for something else on low memory phones, is removed for new data. So, when the app is open again (it was in the background), it still hangs and closes. since an object is not registered, it was in memory and, after its deletion, becomes null, which causes the error.

Is my question to do it with shared preferences? Because I always see it being used with strings, int, bollean, etc. or is there another, more efficient method?

android studio – How to use SharedPreferences access modes?

When we use SharedPreferences, we have for example:

SharedPreferences prefencias = getSharedPreferences(nome, modo);

Where "name" is the name of the preference and "mode" indicates the permission that can be:


What does each of these modes mean? How to use them correctly? In which situations?

Skip settings using SharedPreferences android java

I'm trying to save login variables for use in any part of my application, but I do not understand why this happens with a NULL value.

That's the code I use:

In the login:

    FinalPreferences final pref = getSharedPreferences ("user data", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit ();
editor.putString ("codVendedor", new String (editTextUsername));
editor.putString ("password", new String (editTextPassword));
editor.putString ("remember", new String (remember));
editor.putString ("login", new string (editTextUsername));

And that 's where I have to use it:

                                Remember = new Integer (pref.getString ("Remember", remember)). toString ();
password = pref.getString ("password", password) .toString ();
login = pref.getString ("login", login) .toString ();
codVendedor = pref.getString ("codVendedor", codVendedor) .toString ();

I appreciate your help.