Quick Fix can fix many common issues such as removing unused imports, unused methods or unused variables switching out var with val switching out multiple if– else instances with switch/ when statements and more.
This feature offers you possible solutions to issues with your code based on the current cursor placement and context.
Now, it’s time to move on to the next cool thing that Android Studio can help you do: Find and resolve errors! The Magic of Quick FixĪndroid Studio has a super cool feature called Quick Fix or Intention Actions. Use the key combination ⌥ + ⌘ + N on MacOSX and Ctrl + Alt + N on Windows/Linux to replace all occurrences of the variable with the actual value or methods in the method body: Not only can you use Android Studio shortcuts to extract, but you can also do the opposite: Inlining. Note: You can choose to replace one or all the occurrences of the method body.
You can do this with the key combination of ⌥ + ⌘ + P on MacOSX and Ctrl + Alt + P on Windows/Linux: How about extracting multiple lines of code as a method? Of course you can do this, too! Use the shortcut: ⌥ + ⌘ + M on MacOSX and Ctrl + Alt + M on Windows/Linux: Extracting Method Parametersīut that’s not all! You can go even further by extracting part of the method body as a parameter to the method. Approaching this manually would be cumbersome, to say the least.īut Android Studio simplifies the whole process into a single key combination of ⌥ + ⌘ + V on MacOSX and Ctrl + Alt + V on Windows/Linux: Extracting Methods To do so, use the key combination of ⌘ + F6 on MacOSX and Ctrl + F6 on Windows/Linux.Īll this is very cool, but do you know what would be even better? Being able to extract repeated or complex code into its own method or variable.įor example, say you have a string that’s used repeatedly in your class and you want to replace all the string’s instances with a variable. What about when you’d like to change the method signature?Īndroid Studio can take care of changing the method signature for you by adding, removing, or reordering a method’s argument. Note: Android Studio takes care of all of the instances of the field, method or class when you execute rename. If you’d like move a section of code to its own class or to another package, use the F6 key, as shown below:
If you already have Android Studio 3.4.1 or later open, click File ▸ Import Project and select the top-level project folder you downloaded.
To get started with this tutorial, click the Download Materials button at the top or bottom of the page to download the starter project.
For Windows and Linux, you’ll find the shortcuts to use either in the animated gifs or written out in the tutorial, where necessary. Note: Inside Android Studio, the set keyboard shortcuts correspond to the default MacOSX key mapping.