Lizard & Dog Blog

Android programming guide

So you want to make an app?

We’ve regrouped in this post the best tips we could find to get you started on your journey, as well as links to relevant tutorials on this site and elsewhere.

The basics:

If you’re planning on creating a successful android app, but you don’t have much (or any!) programming experience, my first recommendation would be to start following a java or kotlin tutorial until concepts like classes, methods and primitives feel a bit less occult to you.

Once you’re past this stage, you can start planning your app, so that you can make a roadmap of sorts of all the features you’re gonna cram in that puny android phone!

Is it an online or offline app?

This could be a good starting point for building your roadmap. Is your idea meant to work solely on the phone. Do you need to retrieve data from the internet ? Or to allow some form of communication between users? If so, you will need to handle the back-end (what happens on the servers) as well as the front-end (what happens on the phone) as well as the communication between the two. We’ll go into more details about the back-end, but for now, let’s focus on what’s happening on your phone.

Can you build your app with the default Views provided by Android?

Android presents UI elements on your screen as Views that are contained within Layouts. If you wish to read more about these, go to the official android developer documentation:

https://developer.android.com/reference/android/view/View

If you’ve started using an IDE (like Android-Studio or Eclipse), you’ll have noticed that there are some default views that you can use in your layouts, such as Buttons, EditText and so on. These views offer a slew of customization options and can be used as is in your app, however, they may be missing some of the features you want to implement. These could be visual features , or interaction-related features (i.e. a specific motion you want to implement…). If so you may want to create your own Views by creating custom View classes that either extend the default View class or any existing View or Layout. We talk more about custom Views in an upcoming article.

Once you have a good feel on how view and layouts work, and if you need to implement custom ones for your app, you can move to more advanced functionalities.

Does you app need to access sensors or other functionalities of your phone?

Your android phone is full of features and sensors. Cameras, gyroscopes, GPS chips… most of these can be accessed within your app, provided you give it the proper permissions to do so. We’ll go into a few of these functionalities next:

Do you need to take pictures with your app?

If so, you can get started by using one of the two default APIs that can access the camera on your phone: camera2 or cameraX. camera2 is more complex to implement but offers more control on the core features of your app, but cameraX can be quicker to implement if need be. We talk a bit more about the differences between the two and how to implement camera2 in the following article:

Do you need to access files and internal storage?

To access files and internal storage on Android, you can utilize the file system APIs provided by the Android SDK. These APIs allow you to read, write, and manipulate files and directories. You can use methods such as getFilesDir() and getCacheDir() to obtain file paths for the app’s internal storage directories, or Environment.getExternalStorageDirectory() to access the external storage. Additionally, you can request appropriate permissions, such as READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE, to access files outside of your app’s sandboxed storage.

Do you require to access the user’s location?

If you require access to the user’s location, you can utilize the Location APIs provided by the Android platform. These APIs allow you to retrieve the user’s current location, track location changes, and perform various location-related tasks. You can use the LocationManager class or the newer FusedLocationProviderClient class to obtain the user’s location. However, keep in mind that accessing the user’s location requires appropriate permissions, such as ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, and it’s essential to handle user consent and privacy considerations when using location data in your app.

In addition to the Android platform’s Location APIs, Google provides the Google Location API, which is part of Google Play Services.

What other key features do you need for your app?

Now that we know what functionalities from your phone you want to implement, let’s focus on more complex topics, for which you’ll probably have to resort to libraries.

Is there an image/video manipulation feature in your app?

If you require image or video manipulation features in your app, you can leverage libraries such as OpenCV, Glide, and Picasso.

OpenCV (Open Source Computer Vision Library) is a popular open-source library that provides various computer vision and image processing functions. It offers a wide range of features for image and video manipulation, including image filtering, object detection, face recognition, and more. OpenCV is widely used for complex image processing tasks in Android apps.

Here’s the link to the official OpenCV website : https://opencv.org/

We have also a tutorial on this blog for image manipulation with opencv if you want to create some simple filters:

Note, however that some functionalities of OpenCV rely on other libraries, such as FFMPEG which can be hard to install on Android.

Back to other image-related libraries you could find useful:

Glide is a powerful image loading and caching library for Android that simplifies the process of loading and displaying images in your app. It supports fetching images from various sources, such as network URLs, local storage, and even resources. Glide also provides additional features like image transformations, GIF support, and memory and disk caching.

Picasso is another widely used image loading and caching library for Android. It offers a simple and intuitive API for loading images into ImageView components. Picasso handles the process of fetching, resizing, and caching images efficiently. It also provides features like placeholder images, error handling, and image transformations.

Do you need to handle a lot of custom images/bitmaps?

If your app requires handling a large number of custom images or bitmaps, you may consider using additional libraries or techniques to efficiently manage memory and optimize image handling.

In such cases, libraries like Glide and Picasso mentioned earlier can be helpful. They handle image caching and memory management, ensuring that your app handles images efficiently, especially when dealing with large quantities of custom images.

Additionally, you can implement techniques like downsampling, where you load and display lower-resolution versions of images initially and then load higher-resolution versions only when necessary. This approach helps conserve memory and improves performance.

Do you need to play videos clips in your app?

If your app needs to play video clips, ExoPlayer is a recommended library for multimedia playback on Android.

ExoPlayer is an open-source media player library developed by Google. It provides a flexible and extensible framework for playing various media formats, including video and audio. ExoPlayer supports advanced features like adaptive streaming, media encryption, and media session integration. It offers a comprehensive API for controlling playback, handling media events, and customizing the player’s behavior.

By integrating ExoPlayer into your app, you can handle video playback smoothly, implement playback controls, handle different media formats, and support advanced features like adaptive streaming for optimal playback quality.

Remember to check the official documentation and resources for each library to understand their features, integration process, and compatibility with your app’s requirements.

Do you need to store information in a database?

By default, Android allows you to store data in SQLite, but this can be cumbersome to implement in your app.

If you require persistent data storage in your Android app, the Room library is an excellent choice. Room is an Android architecture component that provides an abstraction layer over SQLite, making it easier to work with databases in Android apps. It offers several advantages over raw SQLite, such as simpler database access, compile-time query verification, and integration with other architecture components.

Where to go next:

If you’ve made it this far, you’ll hopefully have some idea of where to begin for the code part of your app. We’ll delve a bit more in the backend part of app development in the next article so look forward for that if you want to implement features such as group chat or access to a map.

The android developers website also contains a wealth of information and has several good tutorials you can use to further hone your skills as you code your app:

https://developer.android.com/

About us:

https://lizardanddog.com

https://www.cloco.ai

Leave a comment