VS Code has a very useful feature that auto formats code after saving. Although Android Studio doesn’t have it, same can be achieved by using Macros.
Info
Android Studio on Windows
Now from the top menu:
Edit > Macros > Start Macro recording
Then use as many combinations you want. I wanted to remove unused imports and format code on save.
ctrl+alt+o ctrl+alt+s ctrl+s
Finally add a keyboard shortcut:
File > Settings > Keymap select macro and rightclick to add keyboard shortcut
I am using ctrl+shift+s