A couple of months back, version 1.5.1 of Android Studio released, a few days after the first preview of v.2.0. The IDE, which comes with Gradle support, is already considered to be better, more user-friendly than Eclipse (with Apache Ant plugin) by most Android app developers. However, first time coders might find it slightly challenging to use the resources of Android Studio in the best possible manner. The following tips and pointers should come in handy:
- Adding a new file – This can be done directly from the ‘Project’ window. A new resource file (or a code file) can be added by clicking ‘Cmnd + N’ on a Mac system. For Android developers working on Windows systems, ‘Alt + Insert’ is the command to be given. Once the correct directory is chosen, the IDE prompts the user to specify the file type. In most cases, the .xml extension need not be provided.
- Viewing recent files – Android Studio makes it an absolute breeze for Android programmers to check out recently viewed and/or edited files in the code (something that cannot quite be said about Eclipse). Pressing ‘Cmnd + E’ (on Mac) results in a popup dialog box getting displayed – with a list of all the recently opened files. For viewing ONLY the list of recently edited files, the command is ‘Cmnd + Shift + E’. In both the cases, as you start to type, the results begin to get filtered automatically.
- Using the shortcuts – Code completion (initiated by ‘Ctrl + Shift + Space’) is only one of the various convenient keyboard shortcut options that the Android Studio IDE comes with. While working on Android app development projects, all documentations can be viewed by pressing ‘Ctrl + Q’, line indentations can be adjusted with ‘Ctrl + Alt + I’, breakpoints can be viewed (‘Ctrl + Shift + F8’) and toggled (‘Ctrl + F8’), and Live Templates can be implemented with ‘Ctrl + J’. There are many shortcuts for code refactoring, navigation in the IDE (files popups, symbols, classes, bookmarks, etc.), and for compiling & running codes (‘Shift + F9’ and ‘Shift + F10’ perform these functions). With Android Studio, it’s not surprising that the task of making a mobile app takes less time!
Note: There are different shortcut commands for ‘Basic Code Completion’ and ‘Smart Code Completion’ in Android Studio.
- Checking the Productivity Guide – This is a sort of extension of the previous point. The keyboard shortcuts mentioned above helps app developers save time – and with the help of the detailed ‘Productivity Guide’, a clear idea can be obtained about the benefit of these shortcuts. It is present under the ‘Help’ tab, and once launched, it throws up information on how many times a particular feature of the IDE (say, smart code completion) has been used, how much of typing has been avoided with the various shortcuts, and the bugs that have been avoided by using the shortcuts. What’s more, the ‘Productivity Guide’ lets new developers check out all the available features of Android Studio as well. In a nutshell, the Guide is all about tracking the usage of Intellij’s keyboard shortcuts.
- Extracting variables without refactoring – Particularly useful when developers are coding for Android apps on the fly. The ‘Ctrl + Alt + V’ (Windows) and ‘Cmnd + Alt + V’ (Mac) commands allows users to extract variables without going through the process of refactoring. The declaration is generated automatically by Android Studio, doing away with the need for manually typing the declarations. Suggestions are also provided for naming newly declared variables.
Note: A similar resource (‘Cmnd + Alt + P’) is available in Android Studio for extracting parameters without refactoring.
- More efficient emulator in Android Studio 2.0 – Experts from the field of Android app development highlight the emulator in Android Studio as the one mediocrity in the otherwise excellent IDE tool. The Android 2.0 beta has shown that this complaint is likely to get resolved soon. The updated emulator is faster, easier, and more customized – with enhanced multi-touch support (important for app testing…particularly for those that have pinch-and-zoom features). On the toolbar of the new emulator, there are the ‘rotation controls’ – and they have been improved upon as well.
Note: To activate multitouch, long-press ‘Alt’, and click and drag the left mouse button. This zooms in on the point of reference.
- Preparing custom layouts – From previewing layouts while working on XML files, to including new widgets – the powerful ‘layout editor’ of Android Studio lets Android developers perform an array of necessary actions. Near the top of the ‘Preview’ window, there are options present to do different types of modifications, like changing the layout theme and adding preview device(s). Layouts can be viewed (from ‘Preview’) even while working in the ‘Text’ pane. To display or hide new widgets, the ‘Palette’ tab has to be clicked, while developers can also directly switch over to the graphical editor (with ‘Design’). ‘Preview All Screen Sizes’ is the command on the drop-down menu to check app layouts on several devices simultaneously.
- Displaying documentation on mouseover – Mobile app developers who have used the Eclipse IDE invariably vote in favour of this ‘on hover documentation display’ feature. The option is present in Android Studio as well, although here, it is disabled by default. The feature can be activated by browsing to File → Settings → Editor → General, and then, checking the box beside ‘Show Quick doc On Mouse Move’. Once the ‘Apply’ button is clicked, the documentations become visible on hover.
Note: Certain documents, on hover, show a time delay. That can be adjusted easily as well.
- Typing & editing JSON strings – On this IDE, Android app-makers no longer have to worry about managing the large number of backslashes, while typing out a JSON string in their app codes. The advanced ‘Language Injection’ feature of Intellij makes things a whole lot easier. It functions in a two-step process: first, the required fragments are edited inside the JSON editor itself, and then, the fragment is ‘injected’ in the form of ‘Escaped String’ inside the code. There are less chances of making errors here than ever before!
- Sending code content from the parent class or interface to the child – This, in other words, refers to ‘pushing down’ code content from the parent interface/class to a child interface /class. By clicking ‘Ctrl + Alt + Shift + T’ (Windows) or ‘Ctrl + T’ (Mac), mobile app developers can perform this task quickly, and without any risk of data loss. The same steps have to be followed for ‘pulling up’ content from child classes to a parent class. The moved content will become a part of the interfaces (in classes, the content gets removed altogether). The @override annotation is automatically added as well by the IDE.
- Working with images and ‘Code folding’ – Developers and mobile app designers can catch previews of images and/or icons at the time of referencing them inside the app code. The icons /images (in different densities) become viewable in the code margins. Details of asset resources can also be seen by pressing ‘F1’. On the other hand, ‘Code Folding’ is yet another developer-friendly feature in Android Studio – for optimizing the readability of app codes. Portions of the code can be selectively revealed or hidden, and classes can later be expanded to check for updates too.
- Testing and validating URLs – Yet another new feature that has been showcased in Android Studio 2.0 beta. The new version of the IDE has a built-in URL validator – that lets Android app developers test URLs and validate them without any problems. To check URLs in the IDE, programmers have to go to Tools → Android → Google App Indexing Test. The app indexing service in Android Studio ranks high on the reliability and stability counts.
- Changing the theme of the IDE – Not of direct help to app coding, but hey, a visually appealing IDE always gets brownie points. Android Studio wins big regarding this as well – thanks to the option to changing themes. External compatible themes (.jar files) can be downloaded and then imported by going to File → Import Settings. The IDE has to be restarted at this point, following which developers have to browse to Settings → Editor → Colors and fonts. Next up, the new installed theme has to be selected and applied.
- Showing line numbers – This feature is present in both Eclipse and Android Studio – although in the latter, it is even more easy to use. All that app developers have to do is navigate to File → Settings → Editor → Appearance. The box next to ‘Show Line Numbers’ has to be checked next. Line numbers can now be displayed inside the code.
For those only just starting out with Android Studio, the ‘Navigate’ menu is a great help. Methods can be extracted in the IDE with the ‘Cmnd + Alt + M’ command. Making changes to the code, either on the emulator or on devices, will become simpler with the ‘Instant Run’ feature of Android Studio 2.0. It’s not difficult to see why more and more app makers are moving from Eclipse to Android Studio – there are way too many top-notch features in the latter to be ignored!
Latest posts by Hussain Fakhruddin (see all)
- How do mobile apps help small businesses? - October 10, 2019
- Top 15 Mobile App Ideas For 2020 - October 1, 2019
- Top 15 Software Development Trends To Watch Out For In 2020 - September 18, 2019