Tips & Tricks for Android Developers

Nowadays, Android is not just on tens of thousands of different phones and tablets. It’s on your wrist, in your living room, in your car, and as soon we start assigning IP addresses to inanimate objects, it is going to be pretty much everywhere around us. A lot of ground for even an experienced Android developer to cover!

 

Also there are over one million apps on Google Play, not counting Amazon AppStore or markets we are not generally interested in.

 

So, how can an independent developer create a successful app in this huge market with big players? I have no idea, I haven’t made a successful app! But, I have made a cute one, and I’d like to share my story with you.

Few Android Studio Tips, Tricks & Resources you should be familiar with, as an Android Developer

The reason of this article, is to list helpful tips, tricks, shortcuts and resources for Android Studio that will improve your overall efficiency and performance.

 

1.Material Colors theme for Android Logcat

To change Android Studio Logcat you need to go to:Preferences (Settings on Windows / Linux machines) → Editor → Colors & Fonts → Android Logcat and change the foreground color for every type of log.

 

2. Prevent Android Studio Logcat from clearing the log for the current application when it crashes. 

To do that you need to go to theAndroid Monitorpanel and chooseEdit filter configurationon the right side dropdown.

 

3. Apply a proper code style to your IDE (IntelliJ / Android Studio). 

Go toPreferences → Code Style → Javaand in aSchemedropdown you can choose your code style (or set up a new one).

2 styles which are especially worth to mention:

Square Java Code Styles with Android

Google Java Code Style.

 

4. Use split screen for increasing efficiency.

To turn this feature on, you need to right mouse click on the tab of your main screen and choose Split Vertically / Horizontally feature.

But to be as efficient as possible we need to set up a custom keyboard’s shortcut. To do that go to Preferences → Keymap and search for Split Vertically. Then open a context menu and click Add Keyboard Shortcut

It is shown on a gif below. You can define the shortcut for a horizontal split view as well.

 

5. Distraction Free Mode. 

You can enable it by going to: View → Enter Distraction Free Mode

 

6. Use Live Templates

you can use many already defined templates, like for Toasts or if conditions.

you can use your own custom templates. Here is a great reference article by Reto Meier. You can also refer to the IntelliJ IDEA documentation.

 

Learn XML And Java

Extensible markup language (XML) is a markup language that’s the foundation for the Android user interface (UI) and elements. Java is the back-end coding language of the Android platform, and it’s used with binding functionality with your XML layouts. Let’s take a look at a small example.

 

<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android=http://schemas.android.com/apk/res/android"> <data> <variable name="user" type="com.example.User"/> </data> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{user.firstName}"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{user.lastName}"/> </LinearLayout> </layout>

 

This small layout has one data object defined as “User.” For developers used to binding elements in even web design, this should be intuitive for you. The data element is defined in Java, and then the object data is bound to the front-end layout element. In this example, we have a first and last name. The following Java code is an example of a User class used for the binding.

 

public class User { public final String firstName; public final String lastName; public User (String firstName, String lastName){ this.firstName = firstName; this.lastName = lastName; } }

Notice that the constructor takes a first and last name variable and binds the data to the public class properties. When the screen opens on the device, this data is then bound to the front-end elements.

 

Before you get started in Android Application development, you should be expert in both of these technologies. Understanding the fundamentals of XML formats is relatively easy, but Java is an object-oriented language and object-oriented programming (OOP) can be challenging if you’re not familiar with the concept. A newer language and framework, Kotlin, has been introduced to help advance Android app development. It can also be used with legacy Java apps as Kotlin co-operates with Java code.

 

The best way to learn Java is to dive into someone else’s code. GitHub is filled with open-source projects that help you understand Java and OOP concepts. The better your OOP skills are, the easier it will be to create a better coded, less buggy Android app.

 

Understand Memory Limitations

Mobile devices don’t have the high memory limitations that desktops have. In mobile programming, you must learn to code with smaller memory limitations in mind. If you carelessly use memory on an Android device, you run the risk of your app crashing due to “out of memory” errors.

To work around this, use services on the device sparingly and release memory resources when your app is hidden. You can release memory resources by overriding the onTrimMemory event although you should know that this isn’t a magic solution that allows you to ignore other performance optimization throughout your code. The following is a small sample of pseudocode that shows you how to override the event.

@Override public void onTrimMemory(int level) { if (level >= TRIM_MEMORY_MODERATE) {

//release resources here } }

Google also recommends that you avoid or at least reduce the use of bitmaps to lower the memory use when your app is running on the device. 

 

Don’t Use The Emulator For Real-World Testing

The Emulator in Android Studio is good for development and even debugging, but it doesn’t fully simulate a working Android device. You can consider basic environment features with the Emulator, but when it comes to testing, you should always use actual devices.

Of course, this is a huge investment for an Android developer, but it will make the entire development and testing life cycle much more efficient. It also ensures that you’re able to test your applications in various conditions as the user changes settings on the actual device. You can, however, use automated cloud solutions such as Amazon’s Testing platform.

 

Testing should never be taken lightly. It should be a major part when you design and deploy apps for your clients. Fewer bugs means happier users, and it can also mean a more successful app in Google Play. This doesn’t mean that you need to buy every device on the market to test your app on, but you should account for some of the more popular ones and the most common screen sizes.

Top Recommended Freelancers

More than 150,000 freelancers ready to tackle any kind of project


Khalid Ansari

I am a techie at heart and love to explore new technologies. I have helped various companies evaluate their technology stack and help them improve. My responsibilities include "Platform selection and technical design", "Provide options", "Grow technical leader"and "Own the development methodology"

Khalid Ansari | CTO



Related Articles

Writing a Job Description to Hire a Great Android Developer
Writing a Job Description to Hire a Great Android...
Mobile Development

Android is the world’s most popular mobile OS in the mobile market. From phones and watches to cars and TVs, customise your digital life with Android. Many companies preferred Andr...

Read More