I’m Mark, a snow sports enthusiast and I like to trail run, but I’m mostly excited about Android Studio. I’m going to talk to you today about how Android Studio is Wicked Pissah (slang in Boston for meaning awesome).
To get Android Studio, go to d.android.com / Download Android Studio link.
Android Studio has different channels: the stable version, and canary - which contains bleeding edge stuff.
The First Two Things I Do When Pairing With A New Android Developer
When I mentor a new developer, the first thing I do is I set the theme to Darcula. The contrast for coding is better as the color variation is easier for me to consume lots of information. This setting is under Preferences, Appearance.
The second thing I do is to make the IDE show line numbers. You can set this by right clicking on the left gutter of the editor.
Let’s learn some practical keyboard commands to speed up your Android development.
Get more development news like this
I’ll focus on the lower left portion of a Macintosh computer (if you’re on a PC for example, Command will be Control, Option is Alt and Tab is just Tab.).
A useful tool in learning keyboard commands are some plugins. KeyPromoter (Plugin) gives you nagware that pops up telling you the commands and options available.
KeyCastr shows certain keys that you press in the lower left, and it shows the key combinations. This is great if you’re pairing with somebody far and can’t see what you’re doing with your hands.
When I’m in an activity, for example, I can Go To Related Files, and can jump to the layout file.
When I have a layout open, I can find the folder it’s contains in by using Scroll from Source - this automatically opens all the folders and brings you to that file.
Double Shift allows you to search any file and it puts the files that you’ve used most recently up at the top.
cmd-shift-a is a Find Action, so that you can find anything in the project.
cmd-shift-f12 hides superfluous menus and zooms you into your code.
Hierarchy ctrl-h, aka cmd-8, allows you to see the hierarchy of a file.
cmd-alt-t allows you to put the code you’re writing in a for-loop. If you want to un-surround something, meaning if you want to get rid of the enclosing loop, you can cmd-shift-delete (on Macintosh Delete is “Function-Delete”, fn + delete).
It’s neat to see the tools in the Android ecosystem and how they’ve evolved to help us focus on performance. You can use the memory monitor in the tool, CPU monitor, you can also monitor GPU and network.
I tracked some allocations that happened when the app wasn’t performing well. By switching over to layout, you see that transition and you can transfer between size and count. If you want to drill into the actual code and find the code that’s not performing well, look at this allocation and then select Jump to Source.
Android Studio can be a very powerful tool for enhancing your memory mojo.
Breakpoints are amazing when I’m having a problem with the code. You can have temporary breakpoints and you can log in your breakpoints.
If you right click in the gutter on a breakpoint you get a menu which allows to you set certain conditions. In our example, we’ll loop 99 times, but I want to stop at 50. This condition can be set there.
You can also accomplish a fancy condition like breaking at only even bottles. If you set up a lot of logic around your breakpoint, and you don’t want to keep hitting it without losing the logic, you can merely suspend it.
Today the Android Studio emulators are getting really good - they run with multiple cores, they’re fast, you can transfer files to them quicker than you can transfer to physical devices.
Some of the features of the emulator include being able to:
- adjust the volume
- rotate the screen (helpful for checking memory leaks)
- switching locations
- manipulate cellular coverage
- drag files in
At the bottom of the screen, you can see a grayed out lightning bolt, instant run is a great idea in theory. It can take a long time to push your code changes in an APK to an emulated device or a physical device.
The promise of instant run is that you can push just the change code so it goes much quicker, but this does contain some bugs.
Test With The Best
Android Studio allows for some great tests: Espresso tests, unit tests, and running “run with test coverage” command. First I’m going to record an espresso by using cmd-shift-a. Now that it’s recording my actions, if you have a manager that requires a certain number of tests, this will help you with a start as the code is generated for you, and you can manipulate it later.
Unit Test example
I’m going to run the app with the run with coverage command. The magic here is it’s going to take classes that you’re testing against and tell you how many methods and how many lines are covered by tests.
Latest and Greatest
Constraint layout announced to Google I/O last year, February 23 of this year it went 1.0 and a week before then Android Studio 2.3 was released. This was a big milestone moment for Android Studio to have a fully baked version of constraint layout and Android Studio 2.3.
The latest version of Android Studio contains a new version of the App Links Assistant.
The 2.4 preview 5 is now available. In preview 5 is structural search and replace, a powerful tool to refactor code quickly. Suppose there are terrible uses of the Hungarian notation, b for Boolean and m for a member. I can put in a regular expression to search for all instances of b, m followed by a capital letter, followed by any sequence of letters. It’s able to find all instance for B, M, variables, and I’m able to refactor them.
Q & A
Q: What you did for the line numbers just changes it for that one file. If you go to the editor settings in the appearance and check the checkbox, then it’s universal. Mark: You definitely want universal line numbers, use Command Shift A to get into Preferences around line numbers.
Q: The are Android Studio and IntelliJ are related. Mark: IntelliJ is an amazing IDE and Android Studio is built on top of IntelliJ’s product.