change global Contant value

Asked

Viewed 29 times

0

Good afternoon,

I would like to know if it is possible to change the value received by a global constant and set another value. For example, I take the value of the color that is set in the edge lighting settings of Samsung devices, and I want my app to send a new color to this.

public class EdgeLightingSettings {

    public static final class Global {
        public static final String EDGELIGHTING_CUSTOM_COLOR = "edgelighting_custom_color";


    }
}

Here I take the value that is customized by the user in the native edge screen configuration. I want to change this in the code.

Is there a way? O.o

1 answer

0

By definition of language, any constant (that in java is represented by the modifier final) cannot be changed.

If you want a global value, but it can be changed, you should remove the modifier final and keep only the modifier static. In your case, I would:

public class EdgeLightingSettings {

    public static class Global {
        public static String EDGELIGHTING_CUSTOM_COLOR = "edgelighting_custom_color";
    }
}

That way, you could change the value of EDGELIGHTING_CUSTOM_COLOR calling for:

Global.EDGELIGHTING_CUSTOM_COLOR = "Seu valor";
  • Hello @regmoraes, thanks for responding. In case I needed to take the value that is returned from this variable and change. For example, the variable returns a color in int -25751485, and I would like to change this value of int, change the color from where that constant is coming from. I don’t know if I could really explain to you what I wanted to know...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.