In IntelliJ-based IDEs like Android Studio, in Java source codes, there is an option to extract things as constants when possible (final static
). It is in Refactor -> Extract -> Constant
and is accessible via Ctrl+Alt+C.
But I can't find it for Kotlin source codes!
Note 1: I can do it manually as you can see about NUMBER
in the above screenshot (by defining it as a const val
in companion object
).
Note 2: The reverse-action is accomplishable by IDE; it means you can inline NUMBER
with Ctrl+Alt+N.
In IntelliJ-based IDEs like Android Studio, in Java source codes, there is an option to extract things as constants when possible ( final static ). It is in Refactor -> Extract -> Constant and is accessible via Ctrl + Alt + C .
Magic constants are a response to the ever-growing number of APIs in the Android framework, where the state, type of a component, or an action are chosen by providing an int or String constant. For example, setting view visibility with int constants or requiring a system service with String constants.
Press Ctrl+Alt+C to introduce a constant or select Refactor | Extract | Constant.
Unfortunately, this is a known missing feature for now. It's being tracked on the official issue tracker. You can vote for it there =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With