Writing in the front

This article, translated from Android Studio Tips by Philippe Breault, has collected 62 Tips and shortcuts for using Android Studio. According to the application scenarios of these tips, this paper divides these 62 tips into common skills (1-28), coding skills (29-49) and debugging skills (50-62), which are divided into three parts.

Each tip is accompanied by a GIF, but since the original image is slow to load on Google Photo, this article has been transferred to Seven Cows.

Due to my limited ability, there will be some omissions in the translation process. If you find any mistakes or problems, please mention them in the comments. Thank you.

 

The commonly used skill

 

1. Bookmarks

  • Description: this is a useful feature that allows you to bookmark a place so you can jump to it later.
  • Call Menu → Navigate → Bookmarks
  • Shortcut:
    • Add/Remove bookmarks: F3(OS X), F11(Windows/Linux);
    • Add/Remove bookmarks (tagged) : Alt + F3(OS X), Ctrl + F11(Windows/Linux);
    • Show all bookmarks: Cmd + F3(OS X), Shift + F11(Windows/Linux), show all bookmarks list, and is searchable.
    • Previous/Next bookmark: None, you can set shortcut keys in Settings.
  • More: When you specify a mark for a bookmark, you can use the shortcut Ctrl + Mark to quickly jump to the mark, such as Ctrl + 1 to jump to the bookmark marked 1.

Collapse Expand Code Block

  • Description: This action provides a way to hide the parts of the code you don’t care about and display the key code in a concise format. One interesting use is to hide the code of the anonymous inner class and make it look like a Lambda expression.
  • Shortcut: Cmd + “+”/” – “(OS X), Ctrl + Shift +” + “/” – “(Windows/Linux);
  • More: You can set Folding rules in Settig → Editor → General → Code Folding.

Compare With Branch (Git)

  • Description: If your project is managed using Git, you can compare current files or folders with other branches. It’s useful to know how different you are from the main branch.
  • Call: Menu → VCS → Git → Compare With Branch

4. Compare With Clipboard

  • Description: Compares the currently selected section with the contents on the clipboard.
  • Call: right-click the selected part and choose “Compare With Clipboard” from the right-click menu.

5. Context Info

  • Description: The current scope definition exceeds the scroll area, performing this operation will display the context information, usually it displays the class name or inner class name or the current method name. The same applies to XML files.
  • Call Menu → View → Context Info
  • Shortcut key: Alt + Q (Windows/Linux)
  • More: In my opinion, a better use of this feature is to quickly see which parent class the current class inherits or which interface it implements.

6. Find Action

  • Description: Enter the name of an operation for quick lookup, a useful technique for parts of the operation that do not have shortcut keys.
  • Cmd +Shift + A(OS X), Ctrl +Shift + A(Windows/Linux);
  • More: When an action has a shortcut key, it is displayed next to it.

7. Find Complection

  • Description: When you are searching in a file, use autocomplete shortcut keys to suggest words that appear in the current file.
  • Shortcut keys: Cmd + F(OS X),Ctrl + F(Windows/Linux), enter some characters, and then use auto completion;

8. Hide All Panels

  • Description: Switch editor to cover the entire application interface, hide other panels. Performing this operation again will return to the state before hiding.
  • Menu → Window → Active Tool Window → Hide All Windows;
  • Cmd +Shift + F12(OS X), Ctrl +Shift + F12(Windows/Linux);

9. Hightlight All the Things

  • Description: This operation will highlight all occurrences of a character in the current file. This isn’t just a simple match; it actually analyzes the current scope, highlighting only the relevant parts.
  • Menu → Edit → Find → Highlight Left in File;
  • Locate to Previous/Next: Menu → Edit → Find → Find Next/Previous;
  • Shortcut keys: Please view relevant shortcut keys in the menu.
  • More:
    • If you highlight a methodreturnorthrowStatement, which will highlight all exit/end points of the method;
    • If you highlight a class definitionextendorimplementsStatement that will highlight inherited or implemented methods;
    • Highlight aimportStatements also highlight where they are used;
    • Press Esc to exit highlight mode;

10. Jump to Last Tool Window

  • Description: Sometimes you will jump from a tool window to the editor, and then need to go back to the same tool window, for example, you can use this operation to jump to the previous tool window without using the mouse.
  • Shortcut key: F12;

11. Last Edit Location

  • Description: This action will allow you to navigate to the last place you changed, as opposed to clicking the back arrow on the toolbar to return to the previous position, which will return you to the last edit position.
  • Cmd + Shift + Delete(OS X), Ctrl + Shift + Backspace(Windows/Linux);

Move Between Methods and Inner Classes

  • Description: This action jumps the cursor between the names of methods or inner classes in the current file.
  • Navigate → Next Method/Previous Method;
  • Shortcut keys: Ctrl + Up/Down(OS X), Alt + Up/Down(Windows/Linux);

Navigate to Nested files

  • Description:Sometimes you have a stack of files with the same name in different directories, such as in different modulesAndroidManifest.xmlFiles, when you try to locate one of these files, you get a bunch of search results, and you have to figure out which one you want. By prefixing part of the path in the search box and adding a slash, you can find the correct one on your first try.
  • Shortcut keys: Shift + Cmd + O(OS X), Shift + Ctrl + N(Windows/Linux);

Navigate to parent

  • Description: If the cursor is in a method that inherits the overridden parent class, this operation will locate it where the parent class implemented it. Locate the parent class name if the cursor is on the class name.
  • Menu → Navigate → Super Class/Method
  • Shortcut keys: Cmd + U(OS X), Ctrl + U(Windows/Linux);

Open a Panel by Its Number

  • Description: You may have noticed that some panels have a number to the left of their names. Here’s a quick way to open them. If you don’t see the panel name, click the toggle button in the lower left corner of the IDE.
  • Shortcut keys: Cmd + Digit (OS X), Alt + Digit (Windows/Linux);

In addition, you have to Open File files in the outside world.

  • Description: With this shortcut, simply click Tab to open the location of the current file or any upper path to the file.
  • Shortcut keys: Cmd + Tab(OS X), Ctrl + Tab(Windows/Linux);

17. Parameter Info

  • Description: This operation will display the same argument list as you write in the method declaration, which is useful when you want to see the arguments of an existing method. Parameters under the cursor are yellow. If no parameters are yellow, it means that your method call is invalid, probably because one of the parameters was incorrectly assigned. (for example, a floating-point number assigned to an integer parameter). If you are writing a method call and suddenly leave the edit point, when you return, enter a comma to refire the argument information.
  • Shortcut keys: Cmd + P(OS X), Ctrl + U(Windows/Linux);

18. Quick Definition Lookup

  • Description: Have you ever wanted to see the concrete implementation of a method or class, but didn’t want to leave the current interface? This will do it for you.
  • Shortcut keys: Alt + Space/Cmd + Y(OS X), Ctrl + Shift + I(Windows/Linux)

19. Recently Changed Files

  • Description: This operation is similar to the Recents pop-up window, which displays a list of files that have been modified locally recently, arranged by the time they were modified. You can enter characters to filter list results.
  • Shortcut keys: Cmd + Shift + E(OS X), Ctrl + Shift + E(Windows/Linux)

20. Recent Visits (Recents)

  • Description: This operation yields a searchable list of recently accessed files.
  • Shortcut keys: Cmd + E(OS X), Ctrl + E(Windows/Linux)

21. Related Files

  • Description: This action helps to easily jump between layout files and activities/fragments. This is also a shortcut, to the left of the top of the class name/layout.
  • Shortcut keys: Ctrl + Cmd + Up(OS X), Ctrl + Alt + Home(Windows/Linux)

22. Return to the Editor

  • Description:A bunch of keyboard shortcuts will take you away from the editor (Type Hierarchy, Find Lead, etc.). If you want to return to the editor, you have two options:
    1. Esc: This action simply moves the cursor back to the editor.
    2. Shift + Esc: This action closes the current panel and moves the cursor back to the editor.
  • Shortcut:
    • Return to the open panel: Esc
    • Close the panel and return: Shift + Esc

23. Select In

  • Description: Take the current file and ask you where to select it. Imho, the most useful is to open this file in the project structure or explorer. Each operation is prefixed with a number or letter, which can be used to jump quickly. Normally, I’ll use Alt + F1 and press Enter to open the project view, and then use Alt + F1 to find the file in OS X’s Finder. You can use this action in a file or directly in the project view.

  • Shortcut key: Alt + F1;

24. Extend/Shrink Selection

  • Description: This operation gradually enlarges/Narrows the current selection in context. For example, it selects the current variable first, then the current statement, then the entire method, while narrowing selection does the opposite.
  • Shortcut keys: Alt + Up/Down (OS X), Ctrl+W/Ctrl+ Shift +W (Windows, Linux)

25. Sublime Text Multi Selection

  • Description: This feature is awesome! This action recognizes the currently selected string, selects the next same string, and adds a cursor. This means you can have multiple cursors in the same file, and you can type anything at all at the same time.
  • Shortcut keys: Ctrl + G(OS X), Alt + J (Windows, Linux)

26. The File Structure Popup

  • Description: This action shows an outline of the current class and allows quick jumps. You can also filter the results through keyboard input. This is a very efficient way to jump to a given method.

  • More:
    • You can use a hump style to filter options when typing characters. For example, “oCr” will give you “onCreate.”
    • You can decide whether to display anonymous classes by checking multiple boxes. This is useful in cases where you want to jump directly to an onClick method for an OnClickListener.
  • Shortcut keys: Cmd + F12(OS X), Ctrl + F12(Windows/Linux)
  • Menu → Navigate → File Structure

27. The Switcher

  • Description: This shortcut is basically the IDE Alt + TAB/CMD + TAB command. You can use it to switch between navigation tabs or panels. Once the window is open, simply hold down the CTRL key and you can quickly select the corresponding numeric or alphabetic shortcut keys. You can also close a selected TAB or panel by using the Backspace key.

  • Shortcut keys: Ctrl + Tab

28. Version Control Popup (VCS Operations Popup)

  • Description: This action will show you the most common version control actions. If your project is not managed by a version control software such as Git, it will at least give you a local history maintained by the IDE.
  • Shortcut keys: Ctrl + V(OS X), Alt + ‘(Windows/Linux)

 

Coding skills

 

29. Column Selection/Block Selection

  • Description: In normal selection, when you select down, the current line is selected to the end of the line, while in block selection mode, the selection is based on the selected rectangular area.
  • Call: Hold Alt, then drag the mouse to select.
  • Turn on/off block Selection: Menu → Edit → Column Selection Mode
  • Cmd + Shift + 8(OS X), Shift + Alt + Insert(Windows/Linux);

30. Complete Statement

  • Description:This method will generate missing code to complete the statement. Common usage scenarios are as follows:
    • Add a semicolon at the end of the line, even if the cursor is not at the end of the line.
    • Generate parentheses and braces for if, while, and for statements;
    • After method declaration, add curly braces;
  • Call Menu → Edit → Compelete Current Statement
  • Cmd + Shift + Enter(OS X), Ctrl + Shift + Enter(Windows/Linux);
  • More: If a statement has been completed, when you perform the operation, it jumps directly to the next line, even if the cursor is not at the end of the current line.

31. Delete a Line

  • Description: If it is not selected, the line where the cursor is located is deleted; if it is selected, all the selected lines are deleted.
  • Shortcut keys: Cmd + Delete(OS X), Ctrl + Y(Windows/Linux)

32. Duplicate lines

  • Description: Copy the current row and paste it to the next row. This operation does not affect the contents of the clipboard. This command is useful in conjunction with the move line shortcut.
  • Shortcut keys: Cmd + D(OS X), Ctrl + D(Windows/Linux)

33. Write regular expressions (Edit Regex)

  • Description:Writing regular expressions in Java is difficult for a number of reasons:
    • You have to avoid backslashes;
    • To be honest, re is hard;
    • Look at number two.

What can an IDE do for us? Alt + Enter → Check regexp

34. The difference between Using Enter and Tab for Code Completion (Enter vs Tab for Code Completion)

  • Description: When completing code, you can use Enter or Tab to complete the operation, but the two are different.
  • When Enter is used: Inserts the completed code from the cursor without doing anything to the original code.
  • With Tab: Insert the completed code from the cursor and delete the following code until a period, parenthesis, semicolon, or space is encountered.

35. Extract Method

  • Description: Extract a block of code to generate a new method. This technique is useful when you find that a method is so complex that you need to extract a piece of code into a separate method.
  • Call: Menu → Refactor → Extract → Method
  • Shortcuts: Cmd + Alt + M(OS X), Ctrl + Alt + M(Windows/Linux);
  • More: In the Extract code dialog, you can change method modifiers and parameter variable names.

36. Extract Parameter

  • Description: This is a quick operation to extract parameters. This technique is useful when you think you can optimize a method by extracting parameters. This operation takes the current value as an argument to a method and places the old value in the method call as an argument passed in.
  • Call: Menu → Refactor → Extract → Parameter
  • Shortcuts: Cmd + Alt + P(OS X), Ctrl + Alt + P(Windows/Linux);
  • More: By checking “Delegate”, you can keep the old method and reload it to generate a new one.

Extract Variable

  • Description: This is a quick operation to extract variables. This is a handy way to generate variable declarations when you write down values without writing variable declarations, as well as giving a suggested variable name.
  • Call: Menu → Refactor → Extract → Variable
  • Shortcut keys: Cmd + Alt + V(OS X), Ctrl + Alt + V(Windows/Linux)
  • More: When you need to change the type of variable declaration, such as using List instead of ArrayList, you can press Shift + Tab to display all available variable types.

38. Built-in (Inline)

  • Description: What do you do when you start to get a little excited about the extraction operation and suddenly feel there are too many things? This is the opposite of extraction. This operation is valid for methods, fields, parameters, and variables.
  • Call Menu → Refactor → Inline
  • Shortcut keys: Cmd + Alt + N(OS X), Ctrl + Alt + N(Windows/Linux)

39. Join Lines and Literals

  • Description:This is so much better than pressing delete at the end of the line! This operation follows the formatting rules and:
    • Merge two lines of comments and remove the excess//;
    • Merge multi-line strings, remove+And double quotes;
    • Merge field declaration and initialization assignment;
  • Shortcut: Ctrl + Shift + J;

40. Live Templates

  • Dynamic templates are a quick way to insert code snippets. The interesting thing about using dynamic templates is that you can parameterize templates with appropriate default values, which guide you through the parameters when you insert code snippets.
  • More: If you know the abbreviation of the template, you can skip the shortcut keys, just type the abbreviation and use the Tab key to complete.
  • Shortcut keys: Cmd + J(OS X), Ctrl + J(Windows/Linux);

Move Lines Up and Down.

  • Description: Move rows up and down without copying and pasting.
  • Shortcut keys: Alt + Shift + Up/Down;

42. Move Methods

  • Description: This operation is similar to the move row operation, except that it applies to the entire method and can move an entire method block before or after another method without copying or pasting. The actual name for this operation is “move statement,” which means you can move any type of statement, and you can easily reorder fields or inner classes.
  • Shortcut keys: Cmd + Alt + Up/Down(OS X), Ctrl + Shift + Up/Down(Windows/Linux);

43. Negation Completion

  • Description:Sometimes you automatically complete a Boolean value and then go back and add an exclamation mark to the value to complete the reverse operation, now by using input!Instead ofenterComplete the operation, you can skip these tedious operations.
  • Shortcut:When the code completes, press!Can (sometimes need up and down key to select the candidate);

44. Postfix Completion

  • Description: You can think of this operation as a code completion that generates code before the dot, not after it. You actually call this operation just like normal code completion: enter a dot after an expression.

For example, to iterate over a list, you can type mylist. for and press Tab. The for loop will automatically generate code.

  • Call: You can enter a dot after an expression to display a list of candidates, and you can see a list of Postfix keywords in the regular code Completion prompt, as well as in Editor → Postfix Completion.

  • Commonly used suffix-complete keywords are:

    • .for (complete foreach statement)
    • .format(using theString.format()Wrap a string)
    • .cast (wrapping an expression with a cast)

45. Refactor This

  • Description: This operation displays all possible refactoring methods for the currently selected item. This list can be selected quickly with numeric ordinals.

  • Shortcut keys: Ctrl + T(OS X), Ctrl + Alt + Shift + T(Windows/Linux)

46. Rename

  • Description: You can rename variables, fields, methods, classes, packages using this operation. Of course, this ensures that the renaming makes sense for context and doesn’t mindlessly replace names in all files;
  • Shortcut key: Shift + F6
  • More: If you forget this shortcut, you can use the Quick Fix shortcut, which usually includes the rename option.

47. (Semicolon Dot Completion)

  • Description: Code completion this function is great! We’re probably all familiar with the situation where we start typing something, get some suggested options from the IDE, and then use Enter or Tab to select the completion code we want. There is another way to select the completed code: we can enter a dot (.) Or a semicolon (;) . This completes the completion and adds the selected character. This is especially useful when ending a statement completion or making a quick chain-call to a method.
  • Note: If your code completion method requires parameters, these parameters will be skipped.
  • Shortcut key: Autocomplete + “. Or “;”

48. Surround With

  • Description: This operation can wrap a selected block of code around a specific code structure, typically an if statement, loop, try/catch statement, or runnable statement. If you do not select anything, this operation will wrap the current entire row.

  • Shortcut keys: Cmd + Alt + T(OS X), Ctrl + Alt + T(Windows/Linux)

49. Unwrap code

  • Description: This operation removes the surrounding code, which could be an if statement, a while loop, a try/catch statement or even a runnable statement. This is the exact opposite of Surround With.

  • Shortcut keys: Cmd + Shift + Delete(OS X), Ctrl + Shift + Delete(Windows/Linux)

 

Debugging technique

 

Analyze data flow to here

  • Description: This operation will parse the path to the selected variable, parameter, or field. This is a very useful operation when you go into some strange code and try to understand how a parameter is passed here.
  • Menu → Analyze → Analyze Data Flow to Here
  • Shortcut key: None, which can be specified in the Settings.
  • Instead: Analyze data flow from here, which analyzes the path of the currently selected variable down until the end.

Analyze Stacktrace (Analyze Stacktrace)

  • Description: This operation reads a stack trace and makes it clickable as in logcat. This is handy for debugging when you copy a stack trace from a bug report or terminal.
  • Call Menu → Analyze → Analyze Stacktrace
  • Shortcut key: None, which can be specified in the Settings.
  • More: Obfuscated stack traces can also be analyzed using the “ProGuard Unscramble Plugin.”

52. Attach the Debugger

  • Description: Start the debugger at any time, even if you don’t start your application in debug mode. This is convenient because you don’t have to redeploy your application in debug mode to debug it. You can also quickly go into debug mode when someone else is testing your app and suddenly runs into a bug and hands you the device.
  • Call: Click the toolbar icon or Menu → Build → Attach to Android Process
  • Shortcut key: None. You can specify it in Settings or click the corresponding icon on the toolbar.

53. Conditional Breakpoints

  • Description: A breakpoint is triggered when a set condition is met. You can enter a Java Boolean expression based on the current range, and the conditional input box supports code completion.
  • Call: Right-click the breakpoint where you want to fill in the expression, and then enter a Boolean expression.

54. Disable Breakpoints

  • This operation will make a breakpoint. This is handy when you have a breakpoint or log breakpoint with complex conditions that you don’t need at the moment, but don’t need to recreate next time.
  • Call: Hold Alt and click breakpoint.

55. Evaluate Expression

  • Description: This operation can be used to view the contents of a variable and evaluate almost any valid Java expression. Note that if you change the state of a variable, the state will remain after you resume code execution.
  • Shortcut key: in the breakpoint state, the cursor at the variable, press Alt + F8, you can display the calculation expression dialog box.

Inspect Variable

  • Description: This operation examines the value of an expression without opening the evaluate expression dialog box.
  • Shortcut keys: In debugging mode, press Alt and click the expression.

57. Logging Breakpoints

  • Description:This is a breakpoint that prints logs instead of pausing, when you want to print some logs but don’t want to add themlogRedeploy the project after code, which is a very useful operation.
  • Call:Right-click on the breakpoint and cancelSuspendCheck, and then checkLog evaluated ExpressionAnd enter the log information you want to print in the input box.

58. Mark Object

  • Description: When debugging, this operation allows you to add a label to a particular object, which you can quickly identify later. This is a very useful operation in debugging when you look at a bunch of similar objects to see if an object is the same as before.
  • Call:Right-click the object you want to mark and select itMark Object, input label;
  • Shortcut keys: Press F3(OS X) or F11(Windows/Linux) to select an object.

59. Show current Execution Point

  • Description: This action immediately moves your cursor back to current debug.

Usually: 1. You trigger a breakpoint somewhere. 2. Call this shortcut directly to quickly return to the previous step – by – step debugging.

  • Shortcut keys: Alt + F10;

60. Stop the Process

  • Description: This operation terminates the currently running task. If the number of tasks is greater than one, a list is displayed for you to choose from. This is especially useful when terminating debugging or stopping compiling!
  • Shortcut keys: Cmd + F2(OS X), Ctrl + F2(Windows, Linux);

61. Temporary Breakpoints

  • Description: This operation adds a breakpoint that is automatically removed the first time it is hit.

  • Cmd + Alt + Shift + F8(OS X), Ctrl + Alt + Shift + F8(Windows/Linux)

62. The Call Hierarchy Popup

  • Description: This action shows you all possible paths between a method declaration and its invocation.

  • Shortcut keys: Ctrl + Alt + H

Reprinted from: http://www.open-open.com/lib/view/open1458715872710.html

Author: Seachal reference: www.cnblogs.com/ZhangSeacha… If you think reading this blog allows you to some of the harvest, click on the lower left corner of the top piece to 】 and 【 collection this paper 】 if you want more easily found out that my new blog, click on the lower left corner of the “follow me”, if you are interested in my blog content, please continue to pay attention to my blog, I am [Seachal], my GitHub, my CSDN, and my blog for learning and taking notes. I take notes to record the knowledge learned by the author and his thoughts or feelings after learning. The learning process may refer to various materials, if you feel that the article is overquoted, please be sure to inform, so as to deal with quickly. If there are mistakes, don’t hesitate to comment!